phasync
Channels and messaging / SubscribersInterface

Interface

SubscribersInterface

The subscription point of a publisher: each call to subscribe() makes a reader that receives every later message.

Introduction#

Iterating over it reads the messages of a new subscription.

Class synopsis#

interface SubscribersInterface extends \IteratorAggregate, \Traversable {
    /* Methods */
    public SubscribersInterface::subscribe(): SubscriberInterface
}

Methods#

MethodDescription
subscribeCreates a subscription that receives the messages published after this call.

Examples#

Example 1
phasync::run(function () {
    phasync::publisher($subscribers, $publisher);

    $subscription = $subscribers->subscribe();
    $publisher->write('first');
    $publisher->close();

    echo $subscription->read();   // first
});

See also#

  • phasync::publisherCreates a publisher: what is written to $publisher is delivered to every subscription of $subscribers.
  • SubscriberInterfaceA subscription to a publisher: a reading end that receives every message published after it was made.