Replies inline:

On Sat, May 3, 2014 at 4:02 PM, <[email protected]> wrote:

> Can recursive/nested ticks happen in node? I mean functions registered
> with process.nextTick()? Is this possible in user land or node-core only?
>

When you're writing application code, the vast majority of the time you
want to use setImmediate instead of process.nextTick, because setImmediate
does a better job of yielding V8 time to pending I/O operations. That said,
there's no reason you can't call either of setImmediate or process.nextTick
from within the callback you provide to setImmediate or process.nextTick.
In both cases, the provided callback will be added to a queue and handled
as soon as possible, given what "as soon as possible" means, given a
particular operation. For process.nextTick, that means that *all* of the
pending process.nextTick callbacks (included those added "recursively")
will be run before the next turn of the event loop.

Because this can starve I/O or other low-level tasks waiting to be run by
V8, in older versions of Node you will get an error or warning when the
number of callbacks scheduled exceeds a certain depth, which is controlled
by process.maxTickDepth (which defaults to 1000). Note that both
process.nextTick and setImmediate are defined entirely in the JavaScript
side of Node, which leads me to believe that your question below is about
something different from process.nextTick entirely. Also note that how this
is handled varies between stable minor versions of Node, and in 0.11 / 0.12
Trevor Norris modified it to get rid of the maximum tick depth altogether,
which makes this possibly kind of a footgun if you're not very careful
about how you use it. Again: process.nextTick is rarely what you want
unless you're doing fancy, low-level things. setImmediate is the preferred
operation most of the time.

i'm trying to make sense of the below code from node.cc:
>
> if (tick_info->in_tick()) {
>
>     return ret;
>
>   }
>
>
>
>   …
>
>
>
>   tick_info->set_in_tick(true);
>
>
>
>   env->tick_callback_function()->Call(process, 0, NULL);
>
>
>
>   tick_info->set_in_tick(false);
>
>
This guard exists to make sure that all of the queued callbacks are handled
properly within the JavaScript side of Node (as there are additional layers
of core functionality, e.g. domains or asyncListeners, that need to be
wrapped around callback execution). If you're trying to do something fancy
with event loop manipulation in an add-on, you probably need to figure out
how timers and process.nextTick are implemented in src/node.js, which I'll
admit is pretty hairy. Either way, this should only affect you in certain
very limited circumstances. What exactly are you trying to do?

F

-- 
Job board: http://jobs.nodejs.org/
Moderation policy: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
--- 
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].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAHG3qKqs9EyzYwTBYMsj671rOJy%3Dg%3DFj5DJw6bM033PcEP330w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to