final class EvIdle extends EvWatcher (View source)

Class EvIdle

EvIdle watchers trigger events when no other events of the same or higher priority are pending (EvPrepare, EvCheck and other EvIdle watchers do not count as receiving events).

Thus, as long as the process is busy handling sockets or timeouts (or even signals) of the same or higher priority it will not be triggered. But when the process is idle (or only lower-priority watchers are pending), the EvIdle watchers are being called once per event loop iteration - until stopped, that is, or the process receives more events and becomes busy again with higher priority stuff.

Apart from keeping the process non-blocking (which is a useful on its own sometimes), EvIdle watchers are a good place to do "pseudo-background processing", or delay processing stuff to after the event loop has handled all outstanding events.

The most noticeable effect is that as long as any idle watchers are active, the process will not block when waiting for new events.

Properties

bool $is_active from  EvWatcher
bool $is_pending from  EvWatcher
mixed $data from  EvWatcher
int $priority from  EvWatcher

Methods

__construct(mixed $callback, mixed $data = null, int $priority = 0)

Constructs an EvIdle instance.

int
clear()

Clear watcher pending status.

feed(int $revents)

Feeds the given revents set into the event loop.

getLoop()

Returns the loop responsible for the watcher.

invoke(int $revents)

Invokes the watcher callback with the given received events bit mask.

keepalive(bool $value = true)

Configures whether to keep the loop from returning.

setCallback(callable $callback)

Sets new callback for the watcher.

start()

Starts the watcher.

stop()

Stops the watcher.

static EvIdle
createStopped(mixed $callback, mixed $data = null, int $priority = 0)

Creates a stopped EvIdle instance.

Details

__construct(mixed $callback, mixed $data = null, int $priority = 0)

Constructs an EvIdle instance.

Parameters

mixed $callback
mixed $data
int $priority

int clear()

Clear watcher pending status.

If the watcher is pending, this method clears its pending status and returns its revents bitset (as if its callback was invoked). If the watcher isn't pending it does nothing and returns 0.

Sometimes it can be useful to "poll" a watcher instead of waiting for its callback to be invoked, which can be accomplished with this function.

Return Value

int

In case if the watcher is pending, returns revents bitset as if the watcher callback had been invoked. Otherwise returns 0 .

feed(int $revents)

Feeds the given revents set into the event loop.

Feeds the given revents set into the event loop, as if the specified event had happened for the watcher.

Parameters

int $revents

Bit mask of watcher received events.

EvLoop getLoop()

Returns the loop responsible for the watcher.

Return Value

EvLoop

Event loop object responsible for the watcher.

invoke(int $revents)

Invokes the watcher callback with the given received events bit mask.

Parameters

int $revents

Bit mask of watcher received events.

keepalive(bool $value = true)

Configures whether to keep the loop from returning.

Configures whether to keep the loop from returning. With keepalive value set to FALSE the watcher won't keep Ev::run() / EvLoop::run() from returning even though the watcher is active.

Watchers have keepalive value TRUE by default.

Clearing keepalive status is useful when returning from Ev::run() / EvLoop::run() just because of the watcher is undesirable. It could be a long running UDP socket watcher or so.

Parameters

bool $value

With keepalive value set to FALSE the watcher won't keep Ev::run() / EvLoop::run() from returning even though the watcher is active.

setCallback(callable $callback)

Sets new callback for the watcher.

Parameters

callable $callback

void callback ([ object $watcher = NULL [, int $revents = NULL ]] )

start()

Starts the watcher.

Marks the watcher as active. Note that only active watchers will receive events.

stop()

Stops the watcher.

Marks the watcher as inactive. Note that only active watchers will receive events.

final static EvIdle createStopped(mixed $callback, mixed $data = null, int $priority = 0)

Creates a stopped EvIdle instance.

Parameters

mixed $callback
mixed $data
int $priority

Return Value

EvIdle