| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4387ad4 commit bbbb4aa
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1090,7 +1090,7 @@ async function pipeTo(source, ...args) { | |||
| 1090 | 1090 | } else if (transforms.length === 0) { | |
| 1091 | 1091 | // Fast path: no transforms - iterate normalized source directly | |
| 1092 | 1092 | if (signal) { | |
| 1093 | - for await (const batch of normalized) { | ||
| 1093 | + for await (const batch of yieldAbortable(normalized, signal)) { | ||
| 1094 | 1094 | signal.throwIfAborted(); | |
| 1095 | 1095 | const p = writeBatch(batch); | |
| 1096 | 1096 | if (p) await p; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | const common = require('../common'); | |
| 8 | 8 | const assert = require('assert'); | |
| 9 | + const { setTimeout } = require('timers/promises'); | ||
| 9 | 10 | const { pipeTo, from } = require('stream/iter'); | |
| 10 | 11 | ||
| 11 | 12 | // pipeTo with live signal, no transforms — abort mid-stream | |
@@ -30,6 +31,38 @@ async function testPipeToLiveSignalNoTransforms() { | |||
| 30 | 31 | assert.ok(written.length >= 1); | |
| 31 | 32 | } | |
| 32 | 33 | ||
| 34 | + // pipeTo with live signal, no transforms — abort while waiting for next chunk | ||
| 35 | + async function testPipeToLiveSignalNoTransformsPendingNext() { | ||
| 36 | + const ac = new AbortController(); | ||
| 37 | + const reason = new Error('abort reason'); | ||
| 38 | + const writer = { | ||
| 39 | + write: common.mustNotCall(), | ||
| 40 | + }; | ||
| 41 | + const source = { | ||
| 42 | + [Symbol.asyncIterator]() { | ||
| 43 | + return { | ||
| 44 | + next() { | ||
| 45 | + return new Promise(() => {}); | ||
| 46 | + }, | ||
| 47 | + }; | ||
| 48 | + }, | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + setTimeout(10) | ||
| 52 | + .then(() => ac.abort(reason)) | ||
| 53 | + .then(common.mustCall()); | ||
| 54 | + | ||
| 55 | + const result = await Promise.race([ | ||
| 56 | + assert.rejects( | ||
| 57 | + () => pipeTo(source, writer, { signal: ac.signal }), | ||
| 58 | + reason, | ||
| 59 | + ).then(() => 'aborted'), | ||
| 60 | + setTimeout(1000, 'timed out'), | ||
| 61 | + ]); | ||
| 62 | + | ||
| 63 | + assert.strictEqual(result, 'aborted'); | ||
| 64 | + } | ||
| 65 | + | ||
| 33 | 66 | // pipeTo with live signal + transforms — abort mid-stream | |
| 34 | 67 | async function testPipeToLiveSignalWithTransforms() { | |
| 35 | 68 | const ac = new AbortController(); | |
@@ -84,6 +117,7 @@ async function testPipeToLiveSignalWithTransformsCompletes() { | |||
| 84 | 117 | ||
| 85 | 118 | Promise.all([ | |
| 86 | 119 | testPipeToLiveSignalNoTransforms(), | |
| 120 | + testPipeToLiveSignalNoTransformsPendingNext(), | ||
| 87 | 121 | testPipeToLiveSignalWithTransforms(), | |
| 88 | 122 | testPipeToLiveSignalCompletes(), | |
| 89 | 123 | testPipeToLiveSignalWithTransformsCompletes(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments