hhpack/publisher

Simple implementation of Pub/Sub for Hack

Installs: 487

Dependents: 2

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0

Language:Shell

1.3.0 2019-04-15 03:31 UTC

README

Simple implementation of Pub/Sub for Hack.

Latest Stable Version CircleCI Dependency Status License

Basic usage

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());

Run the test

You can run the test with the following command.

composer install
composer test