2015-07-16 01:12:18 +02:00
|
|
|
<?php
|
2015-10-18 09:12:46 +02:00
|
|
|
namespace Icicle\Concurrent\Sync;
|
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
|
|
|
*/
|
2015-12-05 06:50:32 +01:00
|
|
|
interface Synchronizable
|
2015-07-16 01:12:18 +02:00
|
|
|
{
|
|
|
|
/**
|
2015-08-29 08:40:10 +02:00
|
|
|
* @coroutine
|
|
|
|
*
|
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
|
|
|
*
|
2015-08-29 08:40:10 +02:00
|
|
|
* @return \Generator
|
|
|
|
*
|
2015-08-31 11:19:49 +02:00
|
|
|
* @resolve mixed The return value of $callback.
|
2015-07-16 01:12:18 +02:00
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function synchronized(callable $callback): \Generator;
|
2015-07-16 01:12:18 +02:00
|
|
|
}
|