1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-03 10:07:49 +01:00
parallel/lib/Sync/Synchronizable.php

25 lines
888 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
2016-08-23 23:47:40 +02:00
namespace Amp\Parallel\Sync;
2016-08-18 18:04:48 +02:00
2016-11-15 00:43:44 +01:00
use Interop\Async\Promise;
/**
* An object that can be synchronized for exclusive access across contexts.
*/
2016-08-23 01:25:19 +02: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-11-15 00:43:44 +01:00
* @return \Interop\Async\Promise<mixed> Resolves with the return value of $callback or fails if $callback
2016-08-18 18:04:48 +02:00
* throws an exception.
*/
2016-11-15 00:43:44 +01:00
public function synchronized(callable $callback): Promise;
}