Loop
Interfaces, Classes and Traits
- Loop
- A simple eventloop implementation.
Table of Contents
- setTimeout() : mixed
- Executes a function after x seconds.
- setInterval() : array<string|int, mixed>
- Executes a function every x seconds.
- clearInterval() : mixed
- Stops a running interval.
- nextTick() : mixed
- Runs a function immediately at the next iteration of the loop.
- addReadStream() : mixed
- Adds a read stream.
- addWriteStream() : mixed
- Adds a write stream.
- removeReadStream() : mixed
- Stop watching a stream for reads.
- removeWriteStream() : mixed
- Stop watching a stream for writes.
- run() : mixed
- Runs the loop.
- tick() : bool
- Executes all pending events.
- stop() : mixed
- Stops a running eventloop.
- instance() : Loop
- Retrieves or sets the global Loop object.
Functions
setTimeout()
Executes a function after x seconds.
setTimeout(callable $cb, float $timeout) : mixed
Parameters
- $cb : callable
- $timeout : float
Return values
mixed —setInterval()
Executes a function every x seconds.
setInterval(callable $cb, float $timeout) : array<string|int, mixed>
The value this function returns can be used to stop the interval with clearInterval.
Parameters
- $cb : callable
- $timeout : float
Return values
array<string|int, mixed> —clearInterval()
Stops a running interval.
clearInterval(array<string|int, mixed> $intervalId) : mixed
Parameters
- $intervalId : array<string|int, mixed>
Return values
mixed —nextTick()
Runs a function immediately at the next iteration of the loop.
nextTick(callable $cb) : mixed
Parameters
- $cb : callable
Return values
mixed —addReadStream()
Adds a read stream.
addReadStream(resource $stream, callable $cb) : mixed
The callback will be called as soon as there is something to read from the stream.
You MUST call removeReadStream after you are done with the stream, to prevent the eventloop from never stopping.
Parameters
- $stream : resource
- $cb : callable
Return values
mixed —addWriteStream()
Adds a write stream.
addWriteStream(resource $stream, callable $cb) : mixed
The callback will be called as soon as the system reports it's ready to receive writes on the stream.
You MUST call removeWriteStream after you are done with the stream, to prevent the eventloop from never stopping.
Parameters
- $stream : resource
- $cb : callable
Return values
mixed —removeReadStream()
Stop watching a stream for reads.
removeReadStream(resource $stream) : mixed
Parameters
- $stream : resource
Return values
mixed —removeWriteStream()
Stop watching a stream for writes.
removeWriteStream(resource $stream) : mixed
Parameters
- $stream : resource
Return values
mixed —run()
Runs the loop.
run() : mixed
This function will run continuously, until there's no more events to handle.
Return values
mixed —tick()
Executes all pending events.
tick([bool $block = false ]) : bool
If $block is turned true, this function will block until any event is triggered.
If there are now timeouts, nextTick callbacks or events in the loop at all, this function will exit immediately.
This function will return true if there are any events left in the loop after the tick.
Parameters
- $block : bool = false
Return values
bool —stop()
Stops a running eventloop.
stop() : mixed
Return values
mixed —instance()
Retrieves or sets the global Loop object.
instance([Loop $newLoop = null ]) : Loop
Parameters
- $newLoop : Loop = null