phasync
OrderedChannel / subscribe

Method

OrderedChannel::subscribe

Receive what is written from now on, as Swerve::subscribe does.

Description#

public OrderedChannel::subscribe(
    float $maxLag = 30.0,
    ?float $heartbeat = null
): Subscription

The subscription exists once this returns.

Parameters#

$maxLag float = 30.0
Seconds a message may wait before this subscriber reads it
$heartbeat ?float = null
Seconds without a message after which the loop yields null; null for never

Return values#

Subscription

Errors / Exceptions#

ExceptionWhen
InvalidArgumentExceptionFor a name of 0 or over 255 bytes, or starting with "\0"
LogicExceptionDirectly in swerve.php, which the worker serves after: a coroutine started there waits instead

Examples#

Example 1
$subscription = (new OrderedChannel('ledger'))->subscribe(maxLag: 10.0);
foreach ($subscription as $entry) { ... }

See also#

  • OrderedChannel::writeAppend $message to the channel, where every subscriber receives it in the channel's one order.