7.1.0 • Published 1 month ago

@socket-mesh/async-stream-emitter v7.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

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

1 month ago

7.0.7

5 months ago

7.0.6

5 months ago

7.0.5

6 months ago

4.2.9

7 months ago

4.2.8

7 months ago

4.2.10

7 months ago

7.0.4

6 months ago

7.0.3

6 months ago

7.0.2

6 months ago

7.0.1

7 months ago

4.2.7

1 year ago

4.2.6

1 year ago

4.2.5

1 year ago

4.2.4

1 year ago

4.2.3

1 year ago

4.2.2

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago