Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 2.09 KB

README.md

File metadata and controls

56 lines (38 loc) · 2.09 KB

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.