How to use the pause function from readable-stream

Find comprehensive JavaScript readable-stream.pause code examples handpicked from public code repositorys.

The readable-stream.pause method is used to stop the flow of data from a readable stream to a writable stream.

6141
6142
6143
6144
6145
6146
6147
6148
6149

  var ret = _this.push(chunk);

  if (!ret) {
    paused = true;
    stream.pause();
  }
}); // proxy all the other methods.
// important when wrapping filters and duplexes.
fork icon2
star icon3
watch icon1

How does readable-stream.pause work?

The readable-stream.pause() method is used to pause the data stream from emitting "data" events, stopping the flow of data through the stream. When the method is called, the stream's paused property is set to true.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const fs = require("fs");
const { Readable } = require("stream");

const readable = new Readable({
  read(size) {
    // do something
  },
});

// pause the stream
readable.pause();

// resume the stream after 1 second
setTimeout(() => {
  readable.resume();
}, 1000);

In this example, the Readable stream is paused immediately after creation and resumed after a 1-second delay using readable-stream.resume().