Will anyone answer the Node question in the description?
2
100Ṁ60
resolved Sep 23
Resolved
N/A
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.

Get
Ṁ1,000
to start trading!
Sort by:

Invalid premise; the code snippet I posted logs "foo" once. Not sure why it wasn't doing so when I testing earlier. Still confused, but resolving N/A since market criteria are now undefined.

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.

© Manifold Markets, Inc.TermsPrivacy