Socket
Socket
Sign inDemoInstall

async-stream-emitter

Package Overview
Dependencies
3
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    async-stream-emitter

An alternantive to EventEmitter using consumable streams.


Version published
Weekly downloads
34K
increased by2.33%
Maintainers
1
Install size
116 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 20 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc