aeventemitter
v1.0.0
Published
Asynchronous event emitter
Downloads
21
Readme
Async Event Emitter
Library that partialy (for now) implements Node.js' events.EventEmitter
interface but with asynchronous sugar.
Installation
npm i --save aeventemitter
# or
yarn add aeventemitter
Usage example
import AsyncEventEmitter from 'aeventemitter';
const eventEmitter = new AsyncEventEmitter();
const EVENT_NAME = 'event-name';
eventEmitter.on(EVENT_NAME, async (payload: any) => {
// Do your staff
});
eventEmitter.on(EVENT_NAME, async (payload: any) => {
// Do your another staff
});
const { succeeded, noHandlers, errors } = await eventEmitter.emit(EVENT_NAME, { test: 1 });
console.log(succeeded) // True if all handlers were proceeded
console.log(noHandlers) // True if no handlers for event
console.log(errors) // All errors that appears during event handlers execution
Roadmap
- Implement whole
events.EventEmitter
's interface to be compatible with it. - Collect execution results like
Promise.all
- Add more tests