function test() {
console.log("foo")
}
app.get('/testendpoint', (req, res) => {
res.once("drain", test);
res.write((new Array(1000000)).fill("hi").join(","), test);
res.end();
});
Ok, what's going wrong here? I would expect test()
to be called twice, but in reality it's called 0 times.
Resolves NO if no correct answer by tonight.
The drain event on a writable stream only fires if a previous write() returned false (i.e., you hit backpressure) and you're writing once and then immediately calling end(). In most cases write() will return true here, so no backpressure occurs and 'drain' is never emitted. For http.ServerResponse.write(), when the chunk is a string the second argument is the encoding, the callback is the third argument
@underscore I think the intent of writing a huge string (new Array(1000000)).fill("hi").join(",")) is to fill buffer and force 'drain' event, but I'm not familiar with Node enough to know why that doesn't happen.