-2

Does it make sense to say process.nextTick can somewhat help preventing stack overflow ? I mean if we are sure we don't want the code to be executed immediately

Yes ! I placed stack overflow in a question !

redben
  • 5,578
  • 5
  • 47
  • 63

1 Answers1

2

No, you definitely can't say that. For example:

(function stuff () {
  process.nextTick(stuff)
}())

will lead to RangeError: Maximum call stack size exceeded.

vkurchatkin
  • 13,364
  • 2
  • 47
  • 55
  • What kinds of non-recursive stack overflows you want to prevent? – vkurchatkin Dec 15 '13 at 17:17
  • When you have a lot of callbacks (most of which are not really async) – redben Dec 15 '13 at 17:19
  • And how can that cause stack overflow? may be you have an example of code? – vkurchatkin Dec 15 '13 at 17:32
  • Example : http://stackoverflow.com/questions/20243945/nodejs-huge-array-processing-throws-rangeerror-maximum-call-stack-size-exceeded – redben Dec 15 '13 at 17:35
  • FOund my answer here. Thanks anyway. http://stackoverflow.com/questions/16220710/understanding-the-node-js-event-queue-and-process-nexttick – redben Dec 15 '13 at 17:42
  • 1
    Oh, it's basically the same - infinite recursion. `setImmediate` helps. The problem is that `process.nextTick` is not actually async – vkurchatkin Dec 15 '13 at 17:43