phasync
SubscribersInterface / subscribe

Method

SubscribersInterface::subscribe

Creates a subscription that receives the messages published after this call.

Description#

public SubscribersInterface::subscribe(): SubscriberInterface

Return values#

The subscription SubscriberInterface

Examples#

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

    $subscription = $subscribers->subscribe();
    phasync::go(function () use ($subscription) {
        foreach ($subscription as $event) {
            echo "got $event\n";
        }
    });

    $publisher->write('deployed');
    $publisher->close();
});

See also#

  • phasync::publisherCreates a publisher: what is written to $publisher is delivered to every subscription of $subscribers.