1'use strict'; 2const common = require('../common'); 3const stream = require('stream'); 4const assert = require('assert'); 5 6const writable = new stream.Writable({ 7 write: common.mustCall(function(chunk, encoding, cb) { 8 assert.strictEqual( 9 readable._readableState.awaitDrainWriters, 10 null, 11 ); 12 13 if (chunk.length === 32 * 1024) { // first chunk 14 readable.push(Buffer.alloc(34 * 1024)); // above hwm 15 // We should check if awaitDrain counter is increased in the next 16 // tick, because awaitDrain is incremented after this method finished 17 process.nextTick(() => { 18 assert.strictEqual(readable._readableState.awaitDrainWriters, writable); 19 }); 20 } 21 22 process.nextTick(cb); 23 }, 3) 24}); 25 26// A readable stream which produces two buffers. 27const bufs = [Buffer.alloc(32 * 1024), Buffer.alloc(33 * 1024)]; // above hwm 28const readable = new stream.Readable({ 29 read: function() { 30 while (bufs.length > 0) { 31 this.push(bufs.shift()); 32 } 33 } 34}); 35 36readable.pipe(writable); 37