xen-orchestra/@xen-orchestra/emit-async
Julien Fontanet 2a70ebf667 docs: uniformize code blocks
- 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
2023-02-06 11:25:12 +01:00
..
.npmignore feat: unified .npmignore for all packages 2021-04-07 13:58:14 +02:00
.USAGE.md feat(emit-async): pass listener, event and emitter to error handler 2022-05-23 11:31:51 +02:00
index.js feat(emit-async): pass listener, event and emitter to error handler 2022-05-23 11:31:51 +02:00
package.json feat: technical release (#6254) 2022-05-30 17:45:59 +02:00
README.md docs: uniformize code blocks 2023-02-06 11:25:12 +01:00

@xen-orchestra/emit-async

Package Version License PackagePhobia Node compatibility

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.

License

ISC © Vates SAS