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

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

void
setTimeout(int $timeout)

Shall set the timeout in microseconds

Event|null
poll()

Shall poll for the next event

int
count()

No description

Details

void setInput(Input $input)

Shall set input for this event loop

Parameters

Input $input

Return Value

void

void addChannel(Channel $channel)

Shall watch for events on the given channel

Parameters

Channel $channel

Return Value

void

Exceptions

Existence

void addFuture(string $name, Future $future)

Shall watch for events on the given future

Parameters

string $name
Future $future

Return Value

void

Exceptions

Existence

void remove(string $target)

Shall remove the given target

Parameters

string $target

Return Value

void

Exceptions

Existence

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.

Parameters

bool $blocking

Return Value

void

Exceptions

Error

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.

Parameters

int $timeout

Return Value

void

Exceptions

Error

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.

Return Value

Event|null

Exceptions

Timeout

int count()

No description

Return Value

int

The custom count as an integer.

The return value is cast to an integer.