GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: observe abort while awaiting pipeTo source · nodejs/node@d0b830b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • pull.js
  • test/parallel
    • test-stream-iter-pipeto-signal.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/iter/pull.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/pull.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ async function pipeTo(source, ...args) {
10901090
} else if (transforms.length === 0) {
10911091
// Fast path: no transforms - iterate normalized source directly
10921092
if (signal) {
1093-
for await (const batch of normalized) {
1093+
for await (const batch of yieldAbortable(normalized, signal)) {
10941094
signal.throwIfAborted();
10951095
const p = writeBatch(batch);
10961096
if (p) await p;
Collapse file

‎test/parallel/test-stream-iter-pipeto-signal.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-pipeto-signal.js
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const common = require('../common');
88
const assert = require('assert');
9+
const { setTimeout } = require('timers/promises');
910
const { pipeTo, from } = require('stream/iter');
1011

1112
// pipeTo with live signal, no transforms — abort mid-stream
@@ -30,6 +31,38 @@ async function testPipeToLiveSignalNoTransforms() {
3031
assert.ok(written.length >= 1);
3132
}
3233

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+
3366
// pipeTo with live signal + transforms — abort mid-stream
3467
async function testPipeToLiveSignalWithTransforms() {
3568
const ac = new AbortController();
@@ -84,6 +117,7 @@ async function testPipeToLiveSignalWithTransformsCompletes() {
84117

85118
Promise.all([
86119
testPipeToLiveSignalNoTransforms(),
120+
testPipeToLiveSignalNoTransformsPendingNext(),
87121
testPipeToLiveSignalWithTransforms(),
88122
testPipeToLiveSignalCompletes(),
89123
testPipeToLiveSignalWithTransformsCompletes(),

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.