The async/await event emitters, which is a drop-in replacement of the nodejs' builtin events.
$ npm install async-ee
The basic usage of async-ee
is totally the same as the vanilla EventEmitter
. You could simply use async-ee
instead events
in the existing code.
async-ee
extends EventEmitter
, and provides two new methods:
- emitAsync
- emitAsyncSeries
import EventEmitter from 'async-ee'
class MyClass extends EventEmitter {
async doSomething () {
await this.emitAsync('before-event')
const data = await doThings()
await this.emitAsync('after-event', data)
this.emit('sync-event')
return data
}
}
const foo = new MyClass()
.on('before-some-event', async () => await validateFromRemoveServer())
.on('after-event', async data => await doTheTracking(data))
.on('sync-event', () => console.log('did something'))
;(async function () {
const data = await foo.doSomething()
})
Run event handlers with Promise.all()
.
Run async event handlers in sequences.
MIT