2a70ebf667
- add missing syntaxes - don't put prompt if no command outputs to ease copy/paste and use `sh` syntax - always use `$` as prompt and use `console` syntax |
||
---|---|---|
.. | ||
.npmignore | ||
.USAGE.md | ||
index.js | ||
package.json | ||
README.md |
@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.