1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 02:27:55 +01:00
parallel/lib/Sync/Synchronizable.php

26 lines
896 B
PHP
Raw Normal View History

2016-08-22 06:40:48 +02:00
<?php declare(strict_types = 1);
2016-08-18 18:04:48 +02:00
namespace Amp\Concurrent\Sync;
use Interop\Async\Awaitable;
/**
* An object that can be synchronized for exclusive access across contexts.
*/
2015-12-05 06:50:32 +01:00
interface Synchronizable
{
/**
2015-08-31 18:57:55 +02:00
* Asynchronously invokes a callback while maintaining an exclusive lock on the object.
*
* 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.
*
* @param callable<(mixed ...$args): \Generator|mixed> $callback The synchronized callback to invoke.
* The callback may be a regular function or a coroutine.
*
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.
*/
2016-08-18 18:04:48 +02:00
public function synchronized(callable $callback): Awaitable;
}