Skip to content
EventEmitter using async iterable streams
JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Fix naming inconsistency Feb 24, 2019
.gitignore Update README Dec 30, 2018
LICENSE Initial commit Dec 23, 2018
README.md Update README Mar 5, 2019
async-stream-emitter.js v3.0.3 - Add browser builds Mar 17, 2019
async-stream-emitter.min.js v3.0.3 - Add browser builds Mar 17, 2019
gulpfile.js v3.0.3 - Add browser builds Mar 17, 2019
index.js
package.json v4.0.0 Feb 7, 2020

README.md

async-stream-emitter

EventEmitter using ConsumableStream.

Main methods:

  • emit(eventName, data)
  • listener(eventName)
  • closeListener(eventName)
  • closeAllListeners()
  • killListener(eventName)
  • killAllListeners()
  • getListenerBackpressure(eventName)
  • getAllListenersBackpressure()

Usage examples

let emitter = new AsyncStreamEmitter();

(async () => {
  await wait(10);
  emitter.emit('foo', 'hello');

  // This will cause all for-await-of loops for that event to exit.
  // Note that you can also use the 'break' statement inside
  // individual for-await-of loops.
  emitter.closeListener('foo');
})();

(async () => {
  for await (let data of emitter.listener('foo')) {
    // data is 'hello'
  }
  console.log('The listener was closed.');
})();

// Utility function.
function wait(duration) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, duration);
  });
}
You can’t perform that action at this time.