phasync
The event loop / PollerInterface

Interface

PollerInterface

Waits for streams on behalf of the event loop.

Introduction#

Coroutines wait in readable() and writable(); the loop calls poll() when it has nothing else to do, and poll() unparks the waiters whose streams are ready (EventLoop::park()). ext-phasync's phasync\ext\Poller has the same methods; the loop uses it directly when the extension is loaded.

Class synopsis#

interface PollerInterface {
    /* Methods */
    public PollerInterface::poll(float $timeout): void
    public PollerInterface::readable(mixed $stream, float $timeout = PHP_FLOAT_MAX): void
    public PollerInterface::writable(mixed $stream, float $timeout = PHP_FLOAT_MAX): void
}

Methods#

MethodDescription
pollWaits up to $timeout seconds until a waited-for stream is ready, and unparks the waiters of those that are.
readableParks the current coroutine until poll() finds $stream readable.
writableParks the current coroutine until poll() finds $stream writable.