Thanks guys. I emailed Dominic Tarr and he recommends against using
node streams v2 for this stuff as well.
Fedor - thats cute, but say if I call:
s.on('finish', function() { process.exit(); });
s.end();
... My process will exit while data is still in the buffer. The
annoying this is that I can provide that guarantee right now from my
code - I get message acknowledgements, so I can tell you exactly when
all messages have been received by the client. But I can't control
when finish is emitted using streams 2.0 - it gets sent automatically
after the _write() callback is called on the last message. If the
stream 'writes' to an internal memory buffer, those guarantees are all
lost.
Also imagine this code:
middleware = function(req, res) {
// Process messages in the request, then send the responses in the response
s.push(req.body.message);
// When there's data available, send it to the client
s.on('avail', function() {
process.nextTick(function() {
res.end(s.buffer);
});
});
}
then:
s.on('data', function(msg) {
s.write('one');
s.write('two');
});
^--- the request will only be sent 'one' but not 'two' because of how
_write works.
> You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
https://groups.google.com/d/topic/nodejs/l0Lb6XXPhOc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
nodejs+un...@googlegroups.com.