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.
The recommended way to install EventPromise is through composer.
Just create a composer.json file for your project:
{
"require": {
"adirelle/react-event-promise": "@stable"
}
}
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';
}
);
EventPromise is released under the MIT license.