async-stream-emitter
Advanced tools
Comparing version 1.1.0 to 2.0.0
{ | ||
"name": "async-stream-emitter", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "An alternantive to EventEmitter using async iterable streams.", | ||
@@ -31,4 +31,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"stream-demux": "^4.0.4" | ||
"stream-demux": "^5.1.0" | ||
} | ||
} |
# async-stream-emitter | ||
EventEmitter using async iterable streams | ||
EventEmitter using AsyncIterableStream. | ||
## Methods: | ||
- emit(eventName, data) | ||
- listener(eventName) | ||
- closeListener(eventName) | ||
- closeAllListeners() | ||
## Usage examples | ||
```js | ||
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); | ||
}); | ||
} | ||
``` | ||
Note that unlike with `EventEmitter`, you cannot get the count for the number of active listeners at any given time. | ||
This is intentional as it encourages code to be written in a more declarative style and lowers the risk of memory leaks. | ||
If you want to track listeners, you should do it yourself. | ||
The new ECMAScript `Symbol` type should make tracking object references easier: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4899
48
+ Addedasync-iterable-stream@4.0.0(transitive)
+ Addedstream-demux@5.1.0(transitive)
- Removedasync-iterable-stream@3.0.1(transitive)
- Removedstream-demux@4.0.4(transitive)
Updatedstream-demux@^5.1.0