dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

stringify.write() does not invoke the callback supplied #79

Open Twipped opened 9 years ago

Twipped commented 9 years ago

According to the node docs, Writable.write() should take an optional callback for when the data has been written to the stream. This callback never gets invoked on JSONStream.

var JSONStream = require('JSONStream');
var outgoing = JSONStream.stringify();
outgoing.pipe(process.stdout);

setTimeout(function () {console.log('timeout')}, 10000);

console.log('sending');
outgoing.write(['foo'], function () {
    console.log('sent');
    process.exit();
});

Output:

sending
[
["foo"]timeout
dominictarr commented 9 years ago

you shouldn't actually call write directly though, it's better to pipe from a source stream (this module is used by thousands of people and is years old and no one has complained about this before)

JSONStream doesn't do anything async (io) so there isn't really any benefit to providing a callback. it would just callback right away anyway

Twipped commented 9 years ago

Im piping it into a socket. I want confirmation that the socket sent the message. I was under the impression thats what the callback is for.

On Oct 9, 2015, at 5:18 PM, Dominic Tarr notifications@github.com wrote:

you shouldn't actually call write directly though, it's better to pipe from a source stream (this module is used by thousands of people and is years old and no one has complained about this before)

JSONStream doesn't do anything async (io) so there isn't really any benefit to providing a callback. it would just callback right away anyway

— Reply to this email directly or view it on GitHub.

dominictarr commented 9 years ago

It will tell you whether node flushed that to the kernel, but that doesn't mean that the recipient actually received it. the tcp stream could be interrupted after you send it, but before it is received. If you really want a reliable transmission, you need to query the recipient for the latest row received at the start of the session.