2015-07-16 01:12:18 +02:00
|
|
|
<?php
|
|
|
|
namespace Icicle\Concurrent;
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
interface SynchronizableInterface
|
|
|
|
{
|
|
|
|
/**
|
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-08-31 18:57:55 +02:00
|
|
|
* The given callback will be passed the object being synchronized on as the first argument. If the callback throws
|
|
|
|
* an exception, the lock on the object will be immediately released.
|
2015-08-31 11:19:49 +02:00
|
|
|
*
|
2015-09-04 01:10:19 +02:00
|
|
|
* @param callable<(self $synchronized): \Generator|mixed> $callback The synchronized callback to invoke.
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
public function synchronized(callable $callback);
|
|
|
|
}
|