1.0.0 • Published 2 years ago

@xen-orchestra/emit-async v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
2 years ago

@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