how to understand the event of ‘drain’ in stream of Node.js

  Kiến thức lập trình

I am a little bit confused about the below from Node.js documents.

The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.

If false is returned, further attempts to write data to the stream should stop until the
‘drain’ event is emitted.

While a stream is not draining, calls to write() will buffer chunk, and return false. Once all currently buffered chunks are drained (accepted for delivery by the operating system), the ‘drain’ event will be emitted. Once write() returns false, do not write more chunks until the ‘drain’ event is emitted.

LEAVE A COMMENT