1'use strict'; 2const common = require('../common'); 3const stream = require('stream'); 4 5const reader = new stream.Readable(); 6const writer1 = new stream.Writable(); 7const writer2 = new stream.Writable(); 8 9// 560000 is chosen here because it is larger than the (default) highWaterMark 10// and will cause `.write()` to return false 11// See: https://github.com/nodejs/node/issues/2323 12const buffer = Buffer.allocUnsafe(560000); 13 14reader._read = () => {}; 15 16writer1._write = common.mustCall(function(chunk, encoding, cb) { 17 this.emit('chunk-received'); 18 cb(); 19}, 1); 20writer1.once('chunk-received', function() { 21 reader.unpipe(writer1); 22 reader.pipe(writer2); 23 reader.push(buffer); 24 setImmediate(function() { 25 reader.push(buffer); 26 setImmediate(function() { 27 reader.push(buffer); 28 }); 29 }); 30}); 31 32writer2._write = common.mustCall(function(chunk, encoding, cb) { 33 cb(); 34}, 3); 35 36reader.pipe(writer1); 37reader.push(buffer); 38