Files
xen-orchestra/@xen-orchestra/emit-async/README.md
Julien Fontanet 8689cff26b feat(emit-async): handle async listeners (#3416)
Extracted from xo-server.
2018-09-17 10:42:22 +02:00

1.3 KiB

@xen-orchestra/emit-async Build Status

${pkg.description}

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()
ee.emitAsync = emitAsync

ee.on('start', async function () {
  // whatever
})

// similar to EventEmmiter#emit() but returns a promise which resolves when all
// listeners have resolved
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) {
    console.warn(error)
  }
}, 'start')

Development

# Install dependencies
> yarn

# Run the tests
> yarn test

# Continuously compile
> yarn dev

# Continuously run the tests
> yarn dev-test

# Build for production (automatically called by npm install)
> yarn build

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

${pkg.license} © ${pkg.author.name}