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 core _Events system_ is synchronous. This means we can't `await` for listeners and `async` listeners can't be caught. This package extends [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) and enables event emmiters to

latest
Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
63
85.29%
Maintainers
1
Weekly downloads
 
Created
Source

Asynchronous Event Emitter

Nodejs core Events system is synchronous. This means we can't await for listeners and async listeners can't be caught. This package extends EventEmitter and enables event emmiters to await for listeners to resolve in a concise way.

Install

npm install --save asynchronous-emitter

Example

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 main() {
  await events.emit('event');
  console.log('event awaited');
}

main();

FAQs

Package last updated on 18 Sep 2024

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