stream-demux
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "stream-demux", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An iterable asynchronous stream demultiplexer.", | ||
@@ -28,5 +28,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"iterable-async-stream": "^1.0.3", | ||
"iterable-async-stream": "^1.0.7", | ||
"mocha": "^5.0.5" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
const assert = require('assert'); | ||
const StreamDemux = require('../index'); | ||
@@ -12,3 +13,3 @@ const IterableAsyncStream = require('iterable-async-stream'); | ||
describe('StreamDemux tests', () => { | ||
describe('StreamDemux', () => { | ||
let stream; | ||
@@ -22,3 +23,3 @@ let demux; | ||
it('Should work', async () => { | ||
it('should multiplex across a single stream and demultiplex across multiple substreams', async () => { | ||
(async () => { | ||
@@ -31,9 +32,33 @@ for (let i = 0; i < 10; i++) { | ||
demux.end('hello'); | ||
demux.end('abc'); | ||
})(); | ||
let substream = demux.getStream('hello'); | ||
for await (let data of substream) { | ||
console.log('DATA:', data); | ||
} | ||
let receivedHelloPackets = []; | ||
let receivedAbcPackets = []; | ||
await Promise.all([ | ||
(async () => { | ||
let substream = demux.getStream('hello'); | ||
for await (let packet of substream) { | ||
receivedHelloPackets.push(packet); | ||
} | ||
})(), | ||
(async () => { | ||
let substream = demux.getStream('abc'); | ||
for await (let packet of substream) { | ||
receivedAbcPackets.push(packet); | ||
} | ||
})() | ||
]); | ||
assert.equal(receivedHelloPackets.length, 10); | ||
assert.equal(receivedHelloPackets[0], 'world0'); | ||
assert.equal(receivedHelloPackets[1], 'world1'); | ||
assert.equal(receivedHelloPackets[9], 'world9'); | ||
assert.equal(receivedAbcPackets.length, 10); | ||
assert.equal(receivedAbcPackets[0], 'def0'); | ||
assert.equal(receivedAbcPackets[1], 'def1'); | ||
assert.equal(receivedAbcPackets[9], 'def9'); | ||
}); | ||
}); |
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
4216
85