MCPcopy Index your code
hub / github.com/nodejs/node / testShareMultipleConsumers

Function testShareMultipleConsumers

test/parallel/test-stream-iter-share-async.js:26–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24}
25
26async function testShareMultipleConsumers() {
27 async function* gen() {
28 yield [new TextEncoder().encode('chunk1')];
29 yield [new TextEncoder().encode('chunk2')];
30 yield [new TextEncoder().encode('chunk3')];
31 }
32
33 const shared = share(gen(), { highWaterMark: 16 });
34
35 const c1 = shared.pull();
36 const c2 = shared.pull();
37
38 assert.strictEqual(shared.consumerCount, 2);
39
40 const [data1, data2] = await Promise.all([
41 text(c1),
42 text(c2),
43 ]);
44
45 assert.strictEqual(data1, 'chunk1chunk2chunk3');
46 assert.strictEqual(data2, 'chunk1chunk2chunk3');
47}
48
49async function testShareConsumerCount() {
50 const shared = share(from('data'));

Callers 1

Calls 5

shareFunction · 0.85
allMethod · 0.80
genFunction · 0.70
textFunction · 0.50
pullMethod · 0.45

Tested by

no test coverage detected