Skip to content

macedd/asynchronous-emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Nodejs Asynchronous EventEmitter module

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •