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: avoid duplicated endReadableNT scheduling · nodejs/node@e3a06df

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • readable.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/readable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/readable.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const kFlowing = 1 << 24;
130130
const kHasPaused = 1 << 25;
131131
const kPaused = 1 << 26;
132132
const kDataListening = 1 << 27;
133+
const kEndScheduled = 1 << 28;
133134

134135
// TODO(benjamingr) it is likely slower to do it this way than with free functions
135136
function makeBitMapDescriptor(bit) {
@@ -1742,15 +1743,21 @@ function endReadable(stream) {
17421743
const state = stream._readableState;
17431744

17441745
debug('endReadable');
1745-
if ((state[kState] & kEndEmitted) === 0) {
1746-
state[kState] |= kEnded;
1746+
if ((state[kState] & (kEndEmitted | kEndScheduled)) === 0) {
1747+
state[kState] |= kEnded | kEndScheduled;
17471748
process.nextTick(endReadableNT, state, stream);
17481749
}
17491750
}
17501751

17511752
function endReadableNT(state, stream) {
17521753
debug('endReadableNT');
17531754

1755+
// The scheduled tick is running; allow endReadable() to schedule again.
1756+
// This matters both when the 'end' emission is skipped below (e.g. after
1757+
// an unshift()) and when the stream is later reset for reuse
1758+
// (see undestroy()), which clears kEndEmitted but not this flag.
1759+
state[kState] &= ~kEndScheduled;
1760+
17541761
// Check that we didn't get one last unshift.
17551762
if ((state[kState] & (kErrored | kCloseEmitted | kEndEmitted)) === 0 && state.length === 0) {
17561763
state[kState] |= kEndEmitted;

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.