Node.js Stream 可读.isPaused() 方法
readable.isPaused() 方法是 Stream 模块的内置应用程序编程接口,用于检查 Readable 流的当前运行状态。
句法:
readable.isPaused()
参数:此方法不接受任何参数。
返回值:如果Readable状态被暂停则返回true,否则返回false。
下面的示例说明了 Node.js 中readable.isPaused() 方法的使用:
示例 1:
// Node.js program to demonstrate the
// readable.isPaused() method
// Include stream module
const stream = require('stream');
// Constructing readable stream
const readable = new stream.Readable();
// Calling isPaused method
readable.isPaused();
输出:
false
示例 2:
// Node.js program to demonstrate the
// readable.isPaused() method
// Include stream module
const stream = require('stream');
// Constructing readable stream
const readable = new stream.Readable();
// Calling isPaused method
readable.isPaused();
// Calling the pause() function
// to pause readable state
readable.pause();
// Again calling isPaused to check
// if its paued or not
readable.isPaused();
输出:
true
参考: https://nodejs.org/api/stream.html#stream_readable_ispaused