I have this code:
const { Writable } = require('stream')
let writable = new Writable({ highWaterMark: 10 })
writable._write = (chunk, encoding, cb) => {
process.stdout.write(chunk)
}
function writeData(iterations, writer, data, encoding, cb) {
(function write() {
if (!iterations--) return cb()
if (!writer.write(data, encoding)) {
console.log(` <wait>: highWaterMark reached`)
writer.once('drain', write) // same result when I comment this line
}
})()
}
writeData(4, writable, 'String longer than highWaterMark', 'utf8', () => console.log('Done'))
I have the same result when I comment the code that check for a 'drain'
event to write again.
String longer than highWaterMark <wait> highWaterMark reached
It seems like Node does that automatically, so why bother our-self listening for 'drain'
event manually ?