可读流中的 ‘resume’ 事件在调用 stream.resume() 并且 readableFlowing 属性不为真时发出。
用法:
Event:'resume'
返回值:如果 readable.resume() 正在被调用,则它会被发出,否则它不会被发出。
下面的例子说明了在 Node.js 中 resume 事件的使用:
范例1:
// Node.js program to demonstrate the
// readable resume event
// Including fs module
const fs = require('fs');
// Constructing readable stream
const readable = fs.createReadStream("input.txt");
// Handling data event
readable.on('data', (chunk) => {
console.log(`${chunk}`);
});
// Calling pause method
readable.pause()
// Calling resume method
readable.resume();
// Handling resume event
readable.on('resume', () => {
console.log("resume emitted!");
});
console.log("Program ends....");
输出:
Program ends.... resume emitted! GeeksforGeeks
范例2:
// Node.js program to demonstrate the
// readable resume event
// Including fs module
const fs = require('fs');
// Constructing readable stream
const readable = fs.createReadStream("input.txt");
// Handling data event
readable.on('data', (chunk) => {
console.log(`${chunk}`);
// Calling pause method
readable.pause();
// After this any data will be displayed
// after 3 sec.
console.log('No additional data will "
+ "be displayed for 3 seconds.');
// Using setTimeout function
setTimeout(() => {
console.log('Now data starts flowing again.');
// Calling resume method
readable.resume();
// Emitting resume event
readable.on("resume", () => {
console.log("resume emitted!");
});
}, 3000);
});
console.log("Done....");
输出:
Done.... GeeksforGeeks No additional data will be displayed for 3 seconds. Now data starts flowing again. resume emitted!
参考: https://nodejs.org/api/stream.html#stream_event_resume
相关用法
- Node.js Readable Stream readable事件用法及代码示例
- node.js Stream readable.resume()用法及代码示例
- node.js Stream readable.readable用法及代码示例
- Node.js Readable Stream end事件用法及代码示例
- Node.js Readable Stream data事件用法及代码示例
- Node.js Readable Stream close事件用法及代码示例
- Node.js Readable Stream pause事件用法及代码示例
- Node.js Readable Stream error事件用法及代码示例
- node.js Stream readable.pause()用法及代码示例
- node.js Stream readable.isPaused()用法及代码示例
- node.js Stream readable.destroyed用法及代码示例
- node.js Stream readable.destroy()用法及代码示例
- node.js Stream readable.read()用法及代码示例
- node.js Stream readable.readableEncoding用法及代码示例
- node.js Stream readable.readableEnded用法及代码示例
- node.js Stream readable.readableFlowing用法及代码示例
- node.js Stream readable.readableHighWaterMark用法及代码示例
- node.js Stream readable.readableLength用法及代码示例
- node.js Stream readable.readableObjectMode用法及代码示例
- node.js Stream readable.pipe()用法及代码示例
- node.js Stream readable.unpipe()用法及代码示例
- node.js Stream readable.setEncoding()用法及代码示例
- node.js Stream readable.unshift()用法及代码示例
注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Node.js | Readable Stream resume Event。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。