Simple implementation of Pub/Sub for Hack.
Usage is very simple, You just implement Message the Subscriber.
The following are register to MessagePublisher and just publish a message.
namespace domain;
use HHPack\Publisher\Message;
use HHPack\Publisher\Subscribable;
use HHPack\Publisher\MessagePublisher;
final class DomainMessage implements Message
{
}
final class DomainMessageSubscriber implements Subscribable<Message>
{
public async function onDomainMessage(DomainMessage $message) : Awaitable<void>
{
await async_task1();
await async_task2();
}
}
$publisher = new MessagePublisher();
$publisher->registerSubscriber(new DomainMessageSubscriber());
await $publisher->publish(new DomainMessage());
You can run the test with the following command.
composer install
composer test