0.1.2 • Published 9 months ago

asynchronous-emitter v0.1.2

Weekly downloads
71
License
MIT
Repository
github
Last release
9 months ago

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