Interface
SubscriberInterface
A subscription to a publisher: a reading end that receives every message published after it was made.
Introduction#
It is read like any ReadChannelInterface, with read() or foreach. A subscription that falls behind does not hold the publisher or the other subscriptions back, and it ends once the publisher is closed and its messages are read.
Class synopsis#
interface SubscriberInterface extends ReadChannelInterface, \IteratorAggregate, \Traversable, SelectableInterface {
}Examples#
phasync::run(function () {
phasync::publisher($subscribers, $publisher);
$subscription = $subscribers->subscribe();
phasync::go(function () use ($publisher) {
$publisher->write('a');
$publisher->write('b');
$publisher->close();
});
foreach ($subscription as $message) {
echo $message, "\n"; // a, then b
}
});See also#
phasync::publisherCreates a publisher: what is written to$publisheris delivered to every subscription of$subscribers.SubscribersInterface::subscribeCreates a subscription that receives the messages published after this call.