Socket
Book a DemoInstallSign in
Socket

async-ee

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-ee

async-ee

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

async-ee

FAQs

Package last updated on 29 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts