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

Function testShareConsumerCount

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

Source from the content-addressed store, hash-verified

47}
48
49async function testShareConsumerCount() {
50 const shared = share(from('data'));
51
52 assert.strictEqual(shared.consumerCount, 0);
53
54 const c1 = shared.pull();
55 assert.strictEqual(shared.consumerCount, 1);
56
57 const c2 = shared.pull();
58 assert.strictEqual(shared.consumerCount, 2);
59
60 // Cancel detaches all consumers
61 shared.cancel();
62 assert.strictEqual(shared.consumerCount, 0);
63
64 // Both should complete immediately
65 const [data1, data2] = await Promise.all([
66 text(c1),
67 text(c2),
68 ]);
69 assert.strictEqual(data1, '');
70 assert.strictEqual(data2, '');
71}
72
73async function testShareCancel() {
74 const shared = share(from('data'));

Callers 1

Calls 6

shareFunction · 0.85
allMethod · 0.80
fromFunction · 0.50
textFunction · 0.50
pullMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…