Coroutine
class Coroutine
Properties
| static protected bool | $enableReportException | ||
| static protected callable[] | $afterCreatedCallbacks |
Methods
Returns the current coroutine ID.
Register a callback to be called after a coroutine is created.
Register a callback to be executed when the coroutine exits.
Sleep for the given number of seconds.
Returns the parent coroutine ID.
Alias of Coroutine::parentId().
Create a new coroutine.
Create a coroutine with a copy of the parent coroutine context.
Wait for the given coroutines to finish.
Determine if currently running in a coroutine.
Get coroutine statistics.
Determine if a coroutine with the given ID exists.
Get a list of all coroutine IDs.
Enable or disable exception reporting in coroutines.
Flush all static state.
Details
at line 29
static int
id()
Returns the current coroutine ID.
Returns -1 when running in non-coroutine context.
at line 40
static void
afterCreated(callable $callback)
Register a callback to be called after a coroutine is created.
Boot-only. The callback persists in a static property for the worker lifetime and runs for every subsequently created coroutine.
at line 48
static void
defer(callable $callable)
Register a callback to be executed when the coroutine exits.
at line 62
static void
sleep(float $seconds)
Sleep for the given number of seconds.
at line 75
static int
parentId(int|null $coroutineId = null)
Returns the parent coroutine ID.
Returns 0 when running in the top level coroutine.
at line 86
static int
pid(int|null $coroutineId = null)
Alias of Coroutine::parentId().
at line 94
static int
create(callable $callable)
Create a new coroutine.
at line 120
static int
fork(callable $callable, array $keys = [])
Create a coroutine with a copy of the parent coroutine context.
at line 139
static bool
join(array $coroutineIds, float $timeout = -1)
Wait for the given coroutines to finish.
A false return may mean that no supplied coroutine remained active or that the timeout elapsed. It is not a general failure signal.
at line 147
static bool
inCoroutine()
Determine if currently running in a coroutine.
at line 155
static array
stats()
Get coroutine statistics.
at line 163
static bool
exists(int $id)
Determine if a coroutine with the given ID exists.
at line 173
static iterable
list()
Get a list of all coroutine IDs.
at line 184
static void
enableReportException(bool $enableReportException)
Enable or disable exception reporting in coroutines.
Boot-only. The flag persists in a static property for the worker lifetime and applies to every coroutine spawned across the process.
at line 192
static void
flushState()
Flush all static state.
at line 201
static protected void
printLog(Throwable $throwable)
Report an exception through the exception handler.