流管道?"/>
如何暂停和恢复NodeJS流管道?
我正在使用节点的stream.pipleline的承诺版本:
const pipeline = util.promisify(stream.pipeline);
//Create Read,Transform and Write streams....
await pipeline(read, progress,write )
我希望能够以编程方式暂停/恢复整个过程。如何在不中断其中任何一条流的情况下实现这一目标?
回答如下:嗯-实际上很简单-pipeline
在下面使用pipe
,并在流之间转发pause
/ resume
逻辑,所以:
如果您想暂停阅读:
const pipeline = util.promisify(stream.pipeline);
//Create Read,Transform and Write streams....
await pipeline(read, progress,write )
// under some circumstances:
read.pause();
// and then, when you're ready just
read.resume();
除了可写流,您可以在管道中的任何流上暂停。在到达progress
时(基本上在缓冲区已满时),在read
上调用暂停将导致暂停highWaterMark
。
更多推荐
如何暂停和恢复NodeJS流管道?
发布评论