What's the proper way to handle back-pressure in a node.js Transform stream?

前端 未结 6 645
天命终不由人
天命终不由人 2020-12-25 13:55

Intro

These are my first adventures in writing node.js server side. It\'s been fun so far but I\'m having some difficulty understanding the proper way to implement

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-25 14:34

    push will return false if the stream you are writing to (in this case, a file output stream) has too much data buffered. Since you're writing to disk, this makes sense: you are processing data faster than you can write it out.

    When out's buffer is full, your transform stream will fail to push, and start buffering data itself. If that buffer should fill, then inp's will start to fill. This is how things should be working. The piped streams are only going to process data as fast as the slowest link in the chain can handle it (once your buffers are full).

提交回复
热议问题