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: retry read after construct when hwm is 0 · nodejs/node@96554e7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • readable.js
  • test/parallel
    • test-stream-readable-construct-hwm-zero.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
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ function ReadableState(options, stream, isDuplex) {
337337

338338
ReadableState.prototype[kOnConstructed] = function onConstructed(stream) {
339339
if ((this[kState] & kNeedReadable) !== 0) {
340-
maybeReadMore(stream, this);
340+
if (this.highWaterMark === 0)
341+
process.nextTick(nReadingNextTick, stream);
342+
else
343+
maybeReadMore(stream, this);
341344
}
342345
};
343346

Collapse file

‎test/parallel/test-stream-readable-construct-hwm-zero.js‎

Copy file name to clipboard
+82Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const assert = require('node:assert');
6+
const { Duplex, Readable } = require('node:stream');
7+
8+
function create(construct, objectMode = false) {
9+
const chunks = objectMode ? [{ a: 1 }, { b: 2 }] : ['a', 'b'];
10+
return new Readable({
11+
highWaterMark: 0,
12+
objectMode,
13+
construct,
14+
read() {
15+
this.push(chunks.length ? chunks.shift() : null);
16+
},
17+
});
18+
}
19+
20+
create((cb) => setImmediate(cb)).toArray().then(common.mustCall((data) => {
21+
assert.deepStrictEqual(data.map(String), ['a', 'b']);
22+
}));
23+
24+
create((cb) => cb()).toArray().then(common.mustCall((data) => {
25+
assert.deepStrictEqual(data.map(String), ['a', 'b']);
26+
}));
27+
28+
create((cb) => setImmediate(cb), true).toArray().then(common.mustCall((data) => {
29+
assert.deepStrictEqual(data, [{ a: 1 }, { b: 2 }]);
30+
}));
31+
32+
(async () => {
33+
const data = [];
34+
for await (const chunk of create((cb) => setImmediate(cb))) {
35+
data.push(String(chunk));
36+
}
37+
assert.deepStrictEqual(data, ['a', 'b']);
38+
})().then(common.mustCall());
39+
40+
{
41+
const stream = create((cb) => setImmediate(cb));
42+
const data = [];
43+
stream.on('readable', () => {
44+
let chunk;
45+
while ((chunk = stream.read()) !== null) data.push(String(chunk));
46+
});
47+
stream.on('end', common.mustCall(() => {
48+
assert.deepStrictEqual(data, ['a', 'b']);
49+
}));
50+
}
51+
52+
{
53+
const stream = create((cb) => setImmediate(cb));
54+
const data = [];
55+
stream.on('data', (chunk) => data.push(String(chunk)));
56+
stream.on('end', common.mustCall(() => {
57+
assert.deepStrictEqual(data, ['a', 'b']);
58+
}));
59+
}
60+
61+
{
62+
const chunks = ['a', 'b'];
63+
const duplex = new Duplex({
64+
readableHighWaterMark: 0,
65+
construct(cb) {
66+
setImmediate(cb);
67+
},
68+
read() {
69+
this.push(chunks.length ? chunks.shift() : null);
70+
},
71+
write: common.mustNotCall(),
72+
});
73+
duplex.toArray().then(common.mustCall((data) => {
74+
assert.deepStrictEqual(data.map(String), ['a', 'b']);
75+
}));
76+
}
77+
78+
new Readable({
79+
highWaterMark: 0,
80+
construct: common.mustCall((cb) => setImmediate(cb)),
81+
read: common.mustNotCall(),
82+
});

0 commit comments

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