nuxed/event-dispatcher

Nuxed Event Dispatcher

v2.1.0 2020-11-17 21:32 UTC

This package is auto-updated.

Last update: 2024-10-22 07:18:51 UTC


README

Coding standards status Static analysis status Unit tests status Total Downloads Latest Stable Version License

Nuxed Event Dispatcher

The Event Dispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them asynchronously.

Installation

This package can be installed with Composer.

$ composer require nuxed/event-dispatcher

Example

use namespace Nuxed\EventDispatcher;
use namespace Nuxed\EventDispatcher\ListenerProvider;

<<__EntryPoint>>
async function main(): Awaitable<void> {
  $provider = new ListenerProvider\AttachableListenerProvider();

  $provider->listen<SomeEvent>(new SomeEventListener());
  $provider->listen<SomeOtherEvent>(new SomeOtherEventListener());

  $dispatcher = new EventDispatcher\EventDispatcher($provider);

  // dispatch multiple event listeners concurrently
  concurrent {
    // returns the event that was passed, now modified by listeners.
    $someEvent = await $dispatcher->dispatch<SomeEvent>(new SomeEvent());
    $someOtherEvent = await $dispatcher->dispatch<SomeOtherEvent>(new SomeOtherEvent());
  }
}

Security

For information on reporting security vulnerabilities in Nuxed, see SECURITY.md.

License

Nuxed is open-sourced software licensed under the MIT-licensed.