stream: do not unconditionally call _read() on resume() · nodejs/node@ea47189 (original) (raw)

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1 +'use strict';
2 +const common = require('../common');
3 +const { Readable } = require('stream');
4 +
5 +// readable.resume() should not lead to a ._read() call being scheduled
6 +// when we exceed the high water mark already.
7 +
8 +const readable = new Readable({
9 +read: common.mustNotCall(),
10 +highWaterMark: 100
11 +});
12 +
13 +// Fill up the internal buffer so that we definitely exceed the HWM:
14 +for (let i = 0; i < 10; i++)
15 +readable.push('a'.repeat(200));
16 +
17 +// Call resume, and pause after one chunk.
18 +// The .pause() is just so that we don’t empty the buffer fully, which would
19 +// be a valid reason to call ._read().
20 +readable.resume();
21 +readable.once('data', common.mustCall(() => readable.pause()));