phasync
Pool / use

Method

Pool::use

Runs $fn with an instance of its own, and releases the instance afterwards, also when $fn throws.

Description#

public Pool::use(
    Closure $fn,
    float $timeout = PHP_FLOAT_MAX
): mixed

Call discard() inside $fn if the instance broke.

Parameters#

$fn Closure
What to run with the instance
$timeout float = PHP_FLOAT_MAX
Seconds to wait for an instance at most

Return values#

What $fn returned mixed

Errors / Exceptions#

ExceptionWhen
TimeoutExceptionIf no instance became free in time
ThrowableWhat $create or $fn threw

See also#

  • Pool::borrowLends an instance to the caller until it calls release() or discard(), and waits while all are out.