stream-demux 8.0.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +18 -0
- package/package.json +3 -3
- package/test/test.js +68 -0
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ let demux = new StreamDemux();
|
|
|
43
43
|
// the same time.
|
|
44
44
|
// Note that you can optionally pass a number n to the
|
|
45
45
|
// createConsumer(n) method to force the iteration to
|
|
46
|
-
// timeout after n milliseconds of
|
|
46
|
+
// timeout after n milliseconds of inactivity.
|
|
47
47
|
let consumer = demux.stream('def').createConsumer();
|
|
48
48
|
while (true) {
|
|
49
49
|
let packet = await consumer.next();
|
package/index.js
CHANGED
|
@@ -112,6 +112,14 @@ class StreamDemux {
|
|
|
112
112
|
return this._mainStream.hasConsumer(consumerId);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
getConsumerCount(streamName) {
|
|
116
|
+
return this.getConsumerStatsList(streamName).length;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getConsumerCountAll() {
|
|
120
|
+
return this.getConsumerStatsListAll().length;
|
|
121
|
+
}
|
|
122
|
+
|
|
115
123
|
createConsumer(streamName, timeout) {
|
|
116
124
|
let mainStreamConsumer = this._mainStream.createConsumer(timeout);
|
|
117
125
|
|
|
@@ -136,6 +144,16 @@ class StreamDemux {
|
|
|
136
144
|
}
|
|
137
145
|
};
|
|
138
146
|
|
|
147
|
+
let consumerClearActiveTimeout = mainStreamConsumer.clearActiveTimeout;
|
|
148
|
+
mainStreamConsumer.clearActiveTimeout = function (packet) {
|
|
149
|
+
let { value, done } = packet;
|
|
150
|
+
if (done) {
|
|
151
|
+
consumerClearActiveTimeout.apply(this, arguments);
|
|
152
|
+
} else if (value && value.stream === streamName) {
|
|
153
|
+
consumerClearActiveTimeout.apply(this, arguments);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
139
157
|
let consumerGetStats = mainStreamConsumer.getStats;
|
|
140
158
|
mainStreamConsumer.getStats = function () {
|
|
141
159
|
let stats = consumerGetStats.apply(this, arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-demux",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "A consumable stream demultiplexer.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"mocha": "^5.0.5"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"consumable-stream": "^
|
|
32
|
-
"writable-consumable-stream": "^
|
|
31
|
+
"consumable-stream": "^3.0.0",
|
|
32
|
+
"writable-consumable-stream": "^4.0.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/test/test.js
CHANGED
|
@@ -296,6 +296,74 @@ describe('StreamDemux', () => {
|
|
|
296
296
|
assert.equal(packet, null);
|
|
297
297
|
});
|
|
298
298
|
|
|
299
|
+
it('should prevent stream.once() timeout from being reset when writing to other streams', async () => {
|
|
300
|
+
(async () => {
|
|
301
|
+
for (let i = 0; i < 15; i++) {
|
|
302
|
+
await wait(20);
|
|
303
|
+
demux.write('hi', 'test');
|
|
304
|
+
}
|
|
305
|
+
})();
|
|
306
|
+
|
|
307
|
+
let substream = demux.stream('hello');
|
|
308
|
+
|
|
309
|
+
let packet;
|
|
310
|
+
let error;
|
|
311
|
+
try {
|
|
312
|
+
packet = await substream.once(200);
|
|
313
|
+
} catch (err) {
|
|
314
|
+
error = err;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
assert.notEqual(error, null);
|
|
318
|
+
assert.equal(error.name, 'TimeoutError');
|
|
319
|
+
assert.equal(packet, null);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('should prevent stream.once() timeout from being reset when killing other streams', async () => {
|
|
323
|
+
(async () => {
|
|
324
|
+
for (let i = 0; i < 15; i++) {
|
|
325
|
+
await wait(20);
|
|
326
|
+
demux.kill('hi' + i, 'test');
|
|
327
|
+
}
|
|
328
|
+
})();
|
|
329
|
+
|
|
330
|
+
let substream = demux.stream('hello');
|
|
331
|
+
|
|
332
|
+
let packet;
|
|
333
|
+
let error;
|
|
334
|
+
try {
|
|
335
|
+
packet = await substream.once(200);
|
|
336
|
+
} catch (err) {
|
|
337
|
+
error = err;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
assert.notEqual(error, null);
|
|
341
|
+
assert.equal(error.name, 'TimeoutError');
|
|
342
|
+
assert.equal(packet, null);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('should support stream.once() timeout after killing the stream', async () => {
|
|
346
|
+
(async () => {
|
|
347
|
+
await wait(20);
|
|
348
|
+
demux.kill('hello', 'test');
|
|
349
|
+
})();
|
|
350
|
+
|
|
351
|
+
let substream = demux.stream('hello');
|
|
352
|
+
|
|
353
|
+
let start = Date.now();
|
|
354
|
+
|
|
355
|
+
let packet;
|
|
356
|
+
let error;
|
|
357
|
+
try {
|
|
358
|
+
packet = await substream.once(200);
|
|
359
|
+
} catch (err) {
|
|
360
|
+
error = err;
|
|
361
|
+
}
|
|
362
|
+
assert.notEqual(error, null);
|
|
363
|
+
assert.equal(error.name, 'TimeoutError');
|
|
364
|
+
assert.equal(packet, null);
|
|
365
|
+
});
|
|
366
|
+
|
|
299
367
|
it('should support stream.next() method with close command', async () => {
|
|
300
368
|
(async () => {
|
|
301
369
|
for (let i = 0; i < 3; i++) {
|