I'm (finally!) making node-browserchannel extend streams, but I can't 
figure out how to make streams do what I want. (browserchannel is a 
socketio-like library if you haven't seen it - 
https://github.com/josephg/node-browserchannel ).

I'm using a stream in objectMode (because its sending chunked messages). I 
want to be able to have many messages in-flight at a time (I can send many 
messages in reply to a long polling HTTP request from the client). 
According to the spec for streams, My problem is that _write won't let me 
process multiple messages at a time - according to the spec, I should only 
call the _write() callback when the message has been 'flushed', and _write 
doesn't get called again until a process.nextTick() after I call the 
callback.

- If I'm honest and call the callback only after the http response has been 
fired, I can only send one message per http response (_write doesn't get 
called again until the next event loop fires). Having only one message 
in-flight at a time is a _huge_ performance regression.
- If I lie and call the callback immediately, the stream behaves badly. For 
example, if you call end() with a message on the stream, the stream emits 
'finish' long before the messages have actually been delivered to the 
client. You also can't syncronously send a bunch of response messages in 
response to a single request message - unless I do a setTimeout(..., 10) or 
something awful I have no way to bunch the responses into a single HTTP 
response.

Is there a good answer here? I can't think of a decent way to obey the 
streams protocol while still being performant. I could make my own duck 
typed implementation of the Duplex streams API, though I'll probably make 
mistakes and I won't have pipe() support. ... Are there any other good 
options?

-J


-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to