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

Function testShareCancelMidIteration

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

Source from the content-addressed store, hash-verified

85}
86
87async function testShareCancelMidIteration() {
88 // Verify that cancel during iteration stops data flow
89 let sourceReturnCalled = false;
90 const enc = new TextEncoder();
91 async function* gen() {
92 try {
93 yield [enc.encode('a')];
94 yield [enc.encode('b')];
95 yield [enc.encode('c')];
96 } finally {
97 sourceReturnCalled = true;
98 }
99 }
100 const shared = share(gen(), { highWaterMark: 16 });
101 const consumer = shared.pull();
102
103 const items = [];
104 for await (const batch of consumer) {
105 for (const chunk of batch) {
106 items.push(new TextDecoder().decode(chunk));
107 }
108 // Cancel after first batch
109 shared.cancel();
110 }
111 assert.strictEqual(items.length, 1);
112 assert.strictEqual(items[0], 'a');
113
114 await new Promise(setImmediate);
115 assert.strictEqual(sourceReturnCalled, true);
116}
117
118async function testShareCancelWithReason() {
119 const shared = share(from('data'));

Callers 1

Calls 6

shareFunction · 0.85
genFunction · 0.70
decodeMethod · 0.65
pullMethod · 0.45
pushMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…