phasync
Queue / lock

Method

Queue::lock

Runs $callable while holding the lock of this object, and returns what it returns.

Description#

public Queue::lock(
    Closure $callable,
    ?float $timeout = null
): mixed

The lock is reentrant for the coroutine that holds it. Other coroutines wait, and get it in the order they asked.

Parameters#

$callable Closure
What to run with the lock held
$timeout ?float = null
Seconds to wait for the lock at most; null: no limit

Return values#

What $callable returned mixed

Errors / Exceptions#

ExceptionWhen
TimeoutExceptionIf the lock was not acquired in time
ThrowableWhat $callable threw