stream-demux
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "stream-demux", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "An iterable asynchronous stream demultiplexer.", | ||
@@ -31,5 +31,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"async-iterable-stream": "^1.0.1", | ||
"writable-async-iterable-stream": "^1.0.9" | ||
"async-iterable-stream": "^1.0.3", | ||
"writable-async-iterable-stream": "^1.1.0" | ||
} | ||
} |
@@ -5,5 +5,13 @@ # stream-demux | ||
Lets you write data to multiple async iterable streams from a central place without keeping any references to those streams. | ||
The `StreamDemux` class returns streams of type `AsyncIterableStream`. | ||
See https://github.com/SocketCluster/async-iterable-stream | ||
# Usage | ||
## Installation | ||
``` | ||
npm install stream-demux | ||
``` | ||
## Usage | ||
```js | ||
@@ -37,5 +45,14 @@ let demux = new StreamDemux(); | ||
})(); | ||
// Utility function for using setTimeout() with async/await. | ||
function wait(duration) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, duration); | ||
}); | ||
} | ||
``` | ||
# Goal | ||
## Goal | ||
@@ -42,0 +59,0 @@ The goal of this module is to efficiently distribute data to a large number of named asynchronous streams while facilitating programming patterns which decrease the probability of memory leaks. |
@@ -59,3 +59,3 @@ const assert = require('assert'); | ||
it('should support iteraring over a single substream from multiple consumers at the same time', async () => { | ||
it('should support iterating over a single substream from multiple consumers at the same time', async () => { | ||
(async () => { | ||
@@ -96,2 +96,23 @@ for (let i = 0; i < 10; i++) { | ||
}); | ||
it('should support the stream.once() method', async () => { | ||
(async () => { | ||
for (let i = 0; i < 10; i++) { | ||
await wait(10); | ||
demux.write('hello', 'world' + i); | ||
} | ||
demux.end('hello'); | ||
})(); | ||
let substream = demux.stream('hello'); | ||
let packet = await substream.once(); | ||
assert.equal(packet, 'world0'); | ||
packet = await substream.once(); | ||
assert.equal(packet, 'world1'); | ||
packet = await substream.once(); | ||
assert.equal(packet, 'world2'); | ||
}); | ||
}); |
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
7795
135
62