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: respect iter consumer abort signals · nodejs/node@f7adcd8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • broadcast.js
    • share.js
  • test/parallel
    • test-stream-iter-broadcast-basic.js
    • test-stream-iter-share-async.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/broadcast.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class BroadcastImpl {
128128
// own internal AbortController that follows the external signal.
129129
// When no transforms, return rawConsumer directly (controller elided
130130
// per PULL-02 optimization -- no transforms means no signal recipient).
131-
if (transforms.length > 0) {
131+
if (transforms.length > 0 || options?.signal) {
132132
const pullArgs = [...transforms];
133133
if (options?.signal) {
134134
ArrayPrototypePush(pullArgs,
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/share.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ShareImpl {
9797
const { transforms, options } = parsePullArgs(args);
9898
const rawConsumer = this.#createRawConsumer();
9999

100-
if (transforms.length > 0) {
100+
if (transforms.length > 0 || options?.signal) {
101101
if (options) {
102102
return pullWithTransforms(rawConsumer, ...transforms, options);
103103
}
Collapse file

‎test/parallel/test-stream-iter-broadcast-basic.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-broadcast-basic.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ async function testPendingNextSettlesAfterReturn() {
174174
assert.strictEqual(result.value, undefined);
175175
}
176176

177+
async function testPushAbortSignalRejectsPendingNext() {
178+
const ac = new AbortController();
179+
const reason = new Error('push aborted');
180+
const { broadcast: bc } = broadcast();
181+
const iter = bc.push({ signal: ac.signal })[Symbol.asyncIterator]();
182+
183+
const pendingNext = iter.next();
184+
const rejected = assert.rejects(pendingNext, (error) => error === reason);
185+
ac.abort(reason);
186+
187+
await rejected;
188+
}
189+
177190
// =============================================================================
178191
// Writer fail detaches consumers
179192
// =============================================================================
@@ -300,6 +313,7 @@ Promise.all([
300313
testCancelWithReason(),
301314
testCancelWithFalsyReason(),
302315
testPendingNextSettlesAfterReturn(),
316+
testPushAbortSignalRejectsPendingNext(),
303317
testFailDetachesConsumers(),
304318
testWriterFailIdempotent(),
305319
testLateJoinerSeesBufferedData(),
Collapse file

‎test/parallel/test-stream-iter-share-async.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-share-async.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,25 @@ async function testShareAbortSignalWhileSourcePullPending() {
196196
await Promise.all([rejected1, rejected2]);
197197
}
198198

199+
async function testSharePullAbortSignalRejectsPendingNext() {
200+
const ac = new AbortController();
201+
const reason = new Error('pull aborted');
202+
const shared = share(
203+
// eslint-disable-next-line require-yield
204+
(async function* never() {
205+
await new Promise(() => {});
206+
})(),
207+
);
208+
const iter = shared.pull({ signal: ac.signal })[Symbol.asyncIterator]();
209+
210+
const pendingNext = iter.next();
211+
const rejected = assert.rejects(pendingNext, (error) => error === reason);
212+
ac.abort(reason);
213+
214+
await rejected;
215+
shared.cancel();
216+
}
217+
199218
async function testShareAlreadyAborted() {
200219
const shared = share(from('data'), { signal: AbortSignal.abort() });
201220
const consumer = shared.pull();
@@ -340,6 +359,7 @@ Promise.all([
340359
testShareCancelWithReason(),
341360
testShareAbortSignal(),
342361
testShareAbortSignalWhileSourcePullPending(),
362+
testSharePullAbortSignalRejectsPendingNext(),
343363
testShareAlreadyAborted(),
344364
testShareSourceError(),
345365
testShareLateJoiningConsumer(),

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.