functions.php
Table of Contents
Functions
- async() : Future<string|int, T>
- Creates a new fiber to execute the given closure asynchronously. A Future is returned which is completed with the return value of the passed closure or will fail if the closure throws an exception.
- now() : float
- Returns the current time relative to an arbitrary point in time.
- delay() : void
- Non-blocking sleep for the specified number of seconds.
- trapSignal() : int
- Wait for signal(s) in a non-blocking way.
- weakClosure() : TClosure
- Returns a Closure that maintains a weak reference to any $this object held by the Closure (a weak-Closure).
Functions
async()
Creates a new fiber to execute the given closure asynchronously. A Future is returned which is completed with the return value of the passed closure or will fail if the closure throws an exception.
async(Closure $closure, mixed ...$args) : Future<string|int, T>
Parameters
- $closure : Closure
- $args : mixed
-
Arguments forwarded to the closure when starting the fiber.
Tags
Return values
Future<string|int, T>now()
Returns the current time relative to an arbitrary point in time.
now() : float
Return values
float —Time in seconds.
delay()
Non-blocking sleep for the specified number of seconds.
delay(float $timeout[, bool $reference = true ][, Cancellation|null $cancellation = null ]) : void
Parameters
- $timeout : float
-
Number of seconds to wait.
- $reference : bool = true
-
If false, unreference the underlying watcher.
- $cancellation : Cancellation|null = null
-
Cancel waiting if cancellation is requested.
trapSignal()
Wait for signal(s) in a non-blocking way.
trapSignal(int|array<string|int, int> $signals[, bool $reference = true ][, Cancellation|null $cancellation = null ]) : int
Parameters
- $signals : int|array<string|int, int>
-
Signal number or array of signal numbers.
- $reference : bool = true
-
If false, unreference the underlying watcher.
- $cancellation : Cancellation|null = null
-
Cancel waiting if cancellation is requested.
Tags
Return values
int —Caught signal number.
weakClosure()
Returns a Closure that maintains a weak reference to any $this object held by the Closure (a weak-Closure).
weakClosure(TClosure $closure) : TClosure
This allows a class to hold a self-referencing Closure without creating a circular reference that would prevent or delay automatic garbage collection. Invoking the returned Closure after the object is destroyed will throw an instance of Error.
Parameters
- $closure : TClosure