MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-stream-pipe-manual-resume.js:5–31  ·  view source on GitHub ↗
(throwCodeInbetween)

Source from the content-addressed store, hash-verified

3const stream = require('stream');
4
5function test(throwCodeInbetween) {
6 // Check that a pipe does not stall if .read() is called unexpectedly
7 // (i.e. the stream is not resumed by the pipe).
8
9 const n = 1000;
10 let counter = n;
11 const rs = stream.Readable({
12 objectMode: true,
13 read: common.mustCallAtLeast(() => {
14 if (--counter >= 0)
15 rs.push({ counter });
16 else
17 rs.push(null);
18 }, n)
19 });
20
21 const ws = stream.Writable({
22 objectMode: true,
23 write: common.mustCall((data, enc, cb) => {
24 setImmediate(cb);
25 }, n)
26 });
27
28 setImmediate(() => throwCodeInbetween(rs, ws));
29
30 rs.pipe(ws);
31}
32
33test((rs) => rs.read());
34test((rs) => rs.resume());

Calls 2

setImmediateFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…