@xen-orchestra/emit-async

1.0.0 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @xen-orchestra/emit-async

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

3.25 kB

Total Files

3

Last publish

Collaborators

  • b-nollet
  • mathieura
  • florent.beauchamp
  • tgoettelmann
  • julien-f
  • marsaud
  • pdonias
  • olivierlambert
  • benjireis