/react-event-promise

Create ReactPHP promises for events.

Primary LanguagePHPMIT LicenseMIT

EventPromise

EventPromise allows you to easily create Promises that react on events emitted by an EventEmitterInterface.

Listeners are automatically removed when the Promise is fulfilled, rejected or cancelled.

Build Status

Fetch

The recommended way to install EventPromise is through composer.

Just create a composer.json file for your project:

{
    "require": {
        "adirelle/react-event-promise": "@stable"
    }
}

API

Promises are created using the Adirelle\React\EventPromise\EventPromise::listen method:

use \Adirelle\React\EventPromise\EventPromise;
// ...

    EventPromise::listen($someEventEmitter, ['eventToResolve'], ['eventToReject'], ['eventToNotify'])
        ->then(
            function ($arguments) {
                echo 'Event "eventToResolve" emitted';
            },
            function ($arguments) {
                echo 'Event "eventToReject" emitted';
            },
            function ($arguments) {
                echo 'Event "eventToNotify" emitted';
            }
        );

License

EventPromise is released under the MIT license.