Documentation

LoopInterface extends EventListenerInterface

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

run()  : int
Run the event loop until there are no more tasks to perform.
tick()  : void

Constants

ON_FINALLY

Must be emitted at the end of each loop iteration after all other events.

public string ON_FINALLY = 'finally'

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 string 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
int

        
On this page

Search results