MCPcopy Create free account
hub / github.com/nodejs/node / testSignalAsync

Function testSignalAsync

test/parallel/test-stream-iter-to-readable.js:282–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

280// =============================================================================
281
282async function testSignalAsync() {
283 async function* gen() {
284 for (let i = 0; ; i++) {
285 yield [Buffer.from(`chunk${i}`)];
286 }
287 }
288
289 const ac = new AbortController();
290 const readable = toReadable(gen(), { signal: ac.signal });
291
292 const chunks = [];
293 await assert.rejects(async () => {
294 for await (const chunk of readable) {
295 chunks.push(chunk);
296 if (chunks.length >= 3) {
297 ac.abort();
298 }
299 }
300 }, { name: 'AbortError' });
301 assert.ok(chunks.length >= 3);
302 assert.ok(readable.destroyed);
303}
304
305// =============================================================================
306// fromStreamIter: signal already aborted

Callers 1

Calls 5

abortMethod · 0.95
toReadableFunction · 0.85
genFunction · 0.70
pushMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected