LoopInterface
extends
EventListenerInterface
in
The interface is responsible for providing an interface for creating an event loop.
Besides defining a few methods, this interface also implements the EventListenerInterface which allows you to react to certain events.
Table of Contents
Constants
- ON_CALLBACK = 'callback'
- ON_FINALLY = 'finally'
- Must be emitted at the end of each loop iteration after all other events.
- ON_QUERY = 'query'
- ON_SIGNAL = 'signal'
- ON_TICK = 'tick'
- The `tick` event will be emitted whenever all Temporal commands were processed and the internal state is ready to send new data to the server.
Methods
Constants
ON_CALLBACK
public
mixed
ON_CALLBACK
= 'callback'
ON_FINALLY
Must be emitted at the end of each loop iteration after all other events.
public
mixed
ON_FINALLY
= 'finally'
ON_QUERY
public
mixed
ON_QUERY
= 'query'
ON_SIGNAL
public
mixed
ON_SIGNAL
= 'signal'
ON_TICK
The `tick` event will be emitted whenever all Temporal commands were processed and the internal state is ready to send new data to the server.
public
mixed
ON_TICK
= 'tick'
$loop->once('tick', function() {
echo 'tick';
});
This event MAY be emitted any number of times, which may be zero times if this event loop does not send any data at all.
Methods
run()
Run the event loop until there are no more tasks to perform.
public
run() : int
For many applications, this method is the only directly visible invocation on the event loop.
As a rule of thumb, it is usually recommended to attach everything to the same loop instance and then run the loop once at the bottom end of the application.
$loop->run();
This method will keep the loop running until there are no more tasks to perform. In other words: This method will block until the last timer, stream and/or signal has been removed.
Likewise, it is imperative to ensure the application actually invokes this method once. Adding listeners to the loop and missing to actually run it will result in the application exiting without actually waiting for any of the attached listeners.
This method MUST NOT be called while the loop is already running.
Return values
inttick()
public
tick() : void