stream-demux
Advanced tools
Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "stream-demux", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "An iterable asynchronous stream demultiplexer.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,2 +36,16 @@ # stream-demux | ||
(async () => { | ||
// Consume data from 'def' stream. | ||
// Can also work with a while loop for | ||
// older environments. | ||
// Can have multiple loops consuming the same | ||
// stream at the same time. | ||
let asyncIterator = demux.stream('def').getAsyncIterator(); | ||
while (true) { | ||
let packet = await asyncIterator.next(); | ||
if (packet.done) break; | ||
console.log('DEF (while loop):', packet.value); | ||
} | ||
})(); | ||
(async () => { | ||
for (let i = 0; i < 10; i++) { | ||
@@ -38,0 +52,0 @@ await wait(10); |
@@ -110,2 +110,28 @@ const assert = require('assert'); | ||
it('should support iterating over a substream using a while loop', async () => { | ||
(async () => { | ||
for (let i = 0; i < 10; i++) { | ||
await wait(10); | ||
demux.write('hello', 'world' + i); | ||
demux.write('hello', 'foo' + i); | ||
} | ||
demux.end('hello'); | ||
})(); | ||
let receivedPackets = []; | ||
let asyncIterator = demux.stream('hello').createAsyncIterator(); | ||
while (true) { | ||
let packet = await asyncIterator.next(); | ||
if (packet.done) break; | ||
receivedPackets.push(packet.value); | ||
} | ||
assert.equal(receivedPackets.length, 20); | ||
assert.equal(receivedPackets[0], 'world0'); | ||
assert.equal(receivedPackets[1], 'foo0'); | ||
assert.equal(receivedPackets[2], 'world1'); | ||
assert.equal(receivedPackets[3], 'foo1'); | ||
}); | ||
it('should support ending all streams using a single endAll command', async () => { | ||
@@ -112,0 +138,0 @@ (async () => { |
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
14205
320
76