• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const { Readable, Writable } = require('stream');
4
5// Tests that calling .unpipe() un-blocks a stream that is paused because
6// it is waiting on the writable side to finish a write().
7
8const rs = new Readable({
9  highWaterMark: 1,
10  // That this gets called at least 20 times is the real test here.
11  read: common.mustCallAtLeast(() => rs.push('foo'), 20)
12});
13
14const ws = new Writable({
15  highWaterMark: 1,
16  write: common.mustCall(() => {
17    // Ignore the callback, this write() simply never finishes.
18    setImmediate(() => rs.unpipe(ws));
19  })
20});
21
22let chunks = 0;
23rs.on('data', common.mustCallAtLeast(() => {
24  chunks++;
25  if (chunks >= 20)
26    rs.pause();  // Finish this test.
27}));
28
29rs.pipe(ws);
30