Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 873 Bytes

readme.md

File metadata and controls

33 lines (25 loc) · 873 Bytes

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();