Events
final class Events implements Countable, Traversable (View source)
The Event Loop
The Event loop monitors the state of sets of futures and or channels (targets) in order to perform read (Future::value(), Channel::recv()) and write (Channel::send()) operations as the targets become available and the operations may be performed without blocking the event loop.
Methods
Shall remove the given target
Shall set blocking mode
Shall set the timeout in microseconds
Shall poll for the next event
No description
Details
void
setInput(Input $input)
Shall set input for this event loop
void
addChannel(Channel $channel)
Shall watch for events on the given channel
void
addFuture(string $name, Future $future)
Shall watch for events on the given future
void
remove(string $target)
Shall remove the given target
void
setBlocking(bool $blocking)
Shall set blocking mode
By default when events are polled for, blocking will occur (at the PHP level) until the first event can be returned: Setting blocking mode to false will cause poll to return control if the first target polled is not ready.
This differs from setting a timeout of 0 with Events::setTimeout(), since a timeout of 0, while allowed, will cause an exception to be raised, which may be extremely slow or wasteful if what is really desired is non-blocking behaviour.
A non-blocking loop effects the return value of Events::poll(), such that it may be null before all events have been processed.
void
setTimeout(int $timeout)
Shall set the timeout in microseconds
By default when events are polled for, blocking will occur (at the PHP level) until the first event can be returned: Setting the timeout causes an exception to be thrown when the timeout is reached.
This differs from setting blocking mode to false with Events::setBlocking(), which will not cause an exception to be thrown.
Event|null
poll()
Shall poll for the next event
Should there be no targets remaining, null shall be returned Should this be a non-blocking loop, and blocking would occur, null shall be returned Otherwise, the Event returned describes the event.
int
count()
No description