Loop
in package
The `Loop` class exists as a convenient way to get the currently relevant loop
Table of Contents
Properties
- $instance : LoopInterface|null
- $stopped : bool
Methods
- addPeriodicTimer() : TimerInterface
- Enqueue a callback to be invoked repeatedly after the given interval.
- addReadStream() : void
- [Advanced] Register a listener to be notified when a stream is ready to read.
- addSignal() : void
- Register a listener to be notified when a signal has been caught by this process.
- addTimer() : TimerInterface
- Enqueue a callback to be invoked once after the given interval.
- addWriteStream() : void
- [Advanced] Register a listener to be notified when a stream is ready to write.
- cancelTimer() : void
- Cancel a pending timer.
- futureTick() : void
- Schedule a callback to be invoked on a future tick of the event loop.
- get() : LoopInterface
- Returns the event loop.
- removeReadStream() : void
- Remove the read event listener for the given stream.
- removeSignal() : void
- Removes a previously added signal listener.
- removeWriteStream() : void
- Remove the write event listener for the given stream.
- run() : void
- Run the event loop until there are no more tasks to perform.
- stop() : void
- Instruct a running event loop to stop.
Properties
$instance
private
static LoopInterface|null
$instance
$stopped
private
static bool
$stopped
= false
Methods
addPeriodicTimer()
Enqueue a callback to be invoked repeatedly after the given interval.
public
static addPeriodicTimer(float $interval, callable $callback) : TimerInterface
Parameters
- $interval : float
- $callback : callable
Tags
Return values
TimerInterfaceaddReadStream()
[Advanced] Register a listener to be notified when a stream is ready to read.
public
static addReadStream(resource $stream, callable $listener) : void
Parameters
- $stream : resource
- $listener : callable
Tags
addSignal()
Register a listener to be notified when a signal has been caught by this process.
public
static addSignal(int $signal, callable $listener) : void
Parameters
- $signal : int
- $listener : callable
Tags
addTimer()
Enqueue a callback to be invoked once after the given interval.
public
static addTimer(float $interval, callable $callback) : TimerInterface
Parameters
- $interval : float
- $callback : callable
Tags
Return values
TimerInterfaceaddWriteStream()
[Advanced] Register a listener to be notified when a stream is ready to write.
public
static addWriteStream(resource $stream, callable $listener) : void
Parameters
- $stream : resource
- $listener : callable
Tags
cancelTimer()
Cancel a pending timer.
public
static cancelTimer(TimerInterface $timer) : void
Parameters
- $timer : TimerInterface
Tags
futureTick()
Schedule a callback to be invoked on a future tick of the event loop.
public
static futureTick(callable $listener) : void
Parameters
- $listener : callable
Tags
get()
Returns the event loop.
public
static get() : LoopInterface
When no loop is set, it will call the factory to create one.
This method always returns an instance implementing LoopInterface
,
the actual event loop implementation is an implementation detail.
This method is the preferred way to get the event loop and using Factory::create has been deprecated.
Return values
LoopInterfaceremoveReadStream()
Remove the read event listener for the given stream.
public
static removeReadStream(resource $stream) : void
Parameters
- $stream : resource
Tags
removeSignal()
Removes a previously added signal listener.
public
static removeSignal(int $signal, callable $listener) : void
Parameters
- $signal : int
- $listener : callable
Tags
removeWriteStream()
Remove the write event listener for the given stream.
public
static removeWriteStream(resource $stream) : void
Parameters
- $stream : resource
Tags
run()
Run the event loop until there are no more tasks to perform.
public
static run() : void
Tags
stop()
Instruct a running event loop to stop.
public
static stop() : void