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

Function testPullConsumerBreakCleanup

test/parallel/test-stream-iter-pull-async.js:195–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193
194// Pull consumer break (return()) cleans up transform signal
195async function testPullConsumerBreakCleanup() {
196 let signalAborted = false;
197 const trackingTransform = {
198 transform(source, options) {
199 options.signal.addEventListener('abort', () => {
200 signalAborted = true;
201 });
202 return source;
203 },
204 };
205 async function* infiniteSource() {
206 let i = 0;
207 while (true) {
208 yield [new TextEncoder().encode(`chunk${i++}`)];
209 }
210 }
211 // Consumer breaks after first chunk
212 // eslint-disable-next-line no-unused-vars
213 for await (const _ of pull(infiniteSource(), trackingTransform)) {
214 break;
215 }
216 // Give the abort handler a tick to fire
217 await new Promise(setImmediate);
218 assert.strictEqual(signalAborted, true);
219}
220
221// Pull transform returning a Promise
222async function testPullTransformReturnsPromise() {

Callers 1

Calls 2

infiniteSourceFunction · 0.85
pullFunction · 0.70

Tested by

no test coverage detected