0.0.1 • Published 6 years ago

async-ee v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Build Status Coverage

async-ee

The async/await event emitters.

The usage of async-ee is nearly the same as the vanilla EventEmitter, except that asyncEmitter.emit() returns a Promise, while the builtin emitter.emit() returns a boolean value.

Install

$ npm install async-ee

Usage

asyncEmitter.emit() returns a Promise, so that we could use it in async functions.

import EventEmitter from 'async-ee'

class MyClass extends EventEmitter {
  async doSomething () {
    await this.emit('before-event')
    const data = await doThings()
    await this.emit('after-event', data)
    this.emit('sync-event')
    return data
  }
}

const foo = new MyClass()
.on('before-some-event', async () => await validateFromRemoveServer())
.on('after-event', async data => await doTheTracking(data))
.on('sync-event', () => console.log('did something'))

;(async function () {
  const data = await foo.doSomething()
})

emitter.emit(eventName, ...args)

Run event handlers with Promise.all.

emitter.emitSeries(eventName, ...args)

Run event handlers in sequence.

License

MIT

0.0.1

6 years ago

0.0.0

6 years ago