asynchronous-emitter

0.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i asynchronous-emitter

Weekly Downloads

38

Version

0.1.0

License

MIT

Unpacked Size

2.92 kB

Total Files

4

Last publish

Collaborators

  • thiagofm