On Friday, March 29, 2013 7:51:17 AM UTC-6, Ben Noordhuis wrote:
> On Fri, Mar 29, 2013 at 7:54 AM, Andrew Hart
> <[email protected]<javascript:>>
> wrote:
> > I've been trying to use and understand the (new) streams interface, but
> I
> > don't understand when node will or won't terminate my program.
> >
>
> The setTimeout(0) thing is a bug that's fixed in v0.10.2. I'm
> guessing you're running a -pre build that doesn't have the fix.
>
Focusing on streams for a bit by avoiding the setTimeout(0) strangeness on
tag v0.10.2...
Assuming the input does not arrive immediately within 100ms, these both
terminate after reading one line (rather than before reading one line).
node -e
'process.stdin.pipe(process.stdout);setTimeout(function(){process.stdin.unpipe();},
100);'
node -e
'process.stdin.pipe(process.stdout);process.nextTick(function(){process.stdin.unpipe();});'
These both read until cat stops, even though they aren't doing anything
with the input (not sending it to stdout). Why is reading from a pipe
different from reading from a TTY?
cat| node -e
'process.stdin.pipe(process.stdout);setTimeout(function(){process.stdin.unpipe();},
100);'
cat| node -e
'process.stdin.pipe(process.stdout);process.nextTick(function(){process.stdin.unpipe();});'
This *does* copy the input to stdout and doesn't seem to stop. That makes
sense if IO-triggered events take priority over timeout triggered events.
yes| node -e
'process.stdin.pipe(process.stdout);setTimeout(function(){process.stdin.unpipe();},
100);'
This terminates immediately. Finally, this is what I'd expect; unpipe
undoes the effect of pipe and there is nothing to do but terminate. But why
is reading from a yes-pipe different from reading from a cat-pipe?
yes| node -e
'process.stdin.pipe(process.stdout);process.nextTick(function(){process.stdin.unpipe();});'
--
--
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.