MCPcopy Create free account
hub / github.com/nodejs/node / readAndPause

Function readAndPause

test/parallel/test-stream-readable-pause-and-resume.js:23–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21readAndPause();
22
23function readAndPause() {
24 // Does a on(data) -> pause -> wait -> resume -> on(data) ... loop.
25 // Expects on(data) to never fire if the stream is paused.
26 const ondata = common.mustCall((data) => {
27 rs.pause();
28
29 expectedData--;
30 if (expectedData <= 0)
31 return;
32
33 setImmediate(function() {
34 rs.removeListener('data', ondata);
35 readAndPause();
36 rs.resume();
37 });
38 }, 1); // Only call ondata once
39
40 rs.on('data', ondata);
41}
42
43{
44 const readable = new Readable({

Calls 5

pauseMethod · 0.65
resumeMethod · 0.65
setImmediateFunction · 0.50
removeListenerMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected