@xen-orchestra/emit-async
v1.0.0
Published
Emit an event for async listeners to settle
Downloads
11
Maintainers
Keywords
Readme
@xen-orchestra/emit-async
Emit an event for async listeners to settle
Install
Installation of the npm package:
> npm install --save @xen-orchestra/emit-async
Usage
import EE from 'events'
import emitAsync from '@xen-orchestra/emit-async'
const ee = new EE()
// exposing emitAsync on our event emitter
//
// it's not required though and we could have used directly via
// emitAsync.call(ee, event, args...)
ee.emitAsync = emitAsync
ee.on('start', async function () {
// whatever
})
// similar to EventEmmiter#emit() but returns a promise which resolves when all
// listeners have settled
await ee.emitAsync('start')
// by default, it will rejects as soon as one listener reject, you can customise
// error handling though:
await ee.emitAsync(
{
onError(error, event, listener) {
console.warn(error)
},
},
'start'
)
Contributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.