phasync
Synchronized / run

Method

Synchronized::run

Runs $closure once no other coroutine runs a closure for $token, and returns what it returns.

Description#

public static Synchronized::run(
    object|string $token,
    Closure $closure
): mixed

Parameters#

$token object|string
The name of the lock; an object stands for itself
$closure Closure
What to run with the lock held

Return values#

What $closure returned mixed

Errors / Exceptions#

ExceptionWhen
LogicExceptionIf the coroutine that holds the lock asks for it again
ThrowableWhat $closure threw