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');
emitter.closeListener('foo');
})();
(async () => {
for await (let data of emitter.listener('foo')) {
}
console.log('The listener was closed.');
})();
function wait(duration) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, duration);
});
}