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

Function testAbortSignal

test/parallel/test-stream-iter-readable-interop.js:568–589  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

566// =============================================================================
567
568async function testAbortSignal() {
569 let pushCount = 0;
570 const readable = new Readable({
571 read() {
572 this.push(Buffer.from(`sig${pushCount++}`));
573 // Never pushes null - infinite stream
574 },
575 });
576
577 const ac = new AbortController();
578 const chunks = [];
579
580 await assert.rejects(async () => {
581 for await (const batch of pull(readable, { signal: ac.signal })) {
582 chunks.push(...batch);
583 if (chunks.length >= 2) {
584 ac.abort();
585 }
586 }
587 }, { name: 'AbortError' });
588 assert.ok(chunks.length >= 2);
589}
590
591// =============================================================================
592// kValidatedSource identity - from() returns same object for validated sources

Calls 4

abortMethod · 0.95
pullFunction · 0.70
pushMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected