2016-08-22 06:40:48 +02:00
|
|
|
<?php declare(strict_types = 1);
|
2016-08-18 18:04:48 +02:00
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
namespace Amp\Parallel\Sync;
|
2016-08-18 18:04:48 +02:00
|
|
|
|
|
|
|
use Interop\Async\Awaitable;
|
2015-07-16 01:12:18 +02:00
|
|
|
|
|
|
|
/**
|
2015-08-31 11:19:49 +02:00
|
|
|
* An object that can be synchronized for exclusive access across contexts.
|
2015-07-16 01:12:18 +02:00
|
|
|
*/
|
2016-08-23 01:25:19 +02:00
|
|
|
interface Synchronizable {
|
2015-07-16 01:12:18 +02:00
|
|
|
/**
|
2015-08-31 18:57:55 +02:00
|
|
|
* Asynchronously invokes a callback while maintaining an exclusive lock on the object.
|
2015-07-16 01:12:18 +02:00
|
|
|
*
|
2015-10-18 09:12:46 +02:00
|
|
|
* The arguments passed to the callback depend on the implementing object. If the callback throws an exception,
|
|
|
|
* the lock on the object will be immediately released.
|
2015-08-31 11:19:49 +02:00
|
|
|
*
|
2015-10-18 09:12:46 +02:00
|
|
|
* @param callable<(mixed ...$args): \Generator|mixed> $callback The synchronized callback to invoke.
|
2015-09-04 01:10:19 +02:00
|
|
|
* The callback may be a regular function or a coroutine.
|
2015-07-16 01:12:18 +02:00
|
|
|
*
|
2016-08-18 18:04:48 +02:00
|
|
|
* @return \Interop\Async\Awaitable<mixed> Resolves with the return value of $callback or fails if $callback
|
|
|
|
* throws an exception.
|
2015-07-16 01:12:18 +02:00
|
|
|
*/
|
2016-08-18 18:04:48 +02:00
|
|
|
public function synchronized(callable $callback): Awaitable;
|
2015-07-16 01:12:18 +02:00
|
|
|
}
|