stream-demux
Advanced tools
Comparing version 4.0.0 to 4.0.1
{ | ||
"name": "stream-demux", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "An iterable asynchronous stream demultiplexer.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,2 +16,4 @@ # stream-demux | ||
### Consuming using async loops | ||
```js | ||
@@ -41,3 +43,6 @@ let demux = new StreamDemux(); | ||
// the same time. | ||
let asyncIterator = demux.stream('def').getAsyncIterator(); | ||
// Note that you can optionally pass a number n to the | ||
// createAsyncIterator(n) method to force the iteration to | ||
// timeout after n milliseconds of innactivity.s | ||
let asyncIterator = demux.stream('def').createAsyncIterator(); | ||
while (true) { | ||
@@ -70,2 +75,26 @@ let packet = await asyncIterator.next(); | ||
### Consuming using the once method | ||
```js | ||
// Log the next received packet from the abc stream. | ||
(async () => { | ||
// The returned promise never times out. | ||
let packet = await demux.stream('abc').once(); | ||
console.log('Packet:', packet); | ||
})(); | ||
// Same as above, except with a timeout of 10 seconds. | ||
(async () => { | ||
try { | ||
let packet = await demux.stream('abc').once(10000); | ||
console.log('Packet:', packet); | ||
} catch (err) { | ||
// If no packets are written to the 'abc' stream before | ||
// the timeout, an error will be thrown and handled here. | ||
// The err.name property will be 'TimeoutError'. | ||
console.log('Error:', err); | ||
} | ||
})(); | ||
``` | ||
## Goal | ||
@@ -72,0 +101,0 @@ |
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
15533
104