Socket
Book a DemoInstallSign in
Socket

asynchronous-emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asynchronous-emitter

Nodejs Events runs in synchronous mode. This means that event listeners that are `async` cannot be `await`ed. This package extends the [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) class and enables the promises to chain i

Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Asynchronous Event Emitter

Nodejs Events runs in synchronous mode. This means that event listeners that are async cannot be awaited. This package extends the EventEmitter class and enables the promises to chain into the emit event.

const AsyncEventEmitter = require('asynchronous-emitter');
const events = new AsyncEventEmitter();

// it's the same core EventEmitter apis and behavior
events.on('event', () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log('event will resolve');
      resolve();
    }, 100);
  });
});

// but it await events
async function test() {
  await events.emit('event');
  console.log('event awaited');
}
test();

FAQs

Package last updated on 13 Mar 2019

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