Wednesday, February 1, 2012

RangeError: Maximum call stack size exceeded

One difficulty in node.js occurs with the asynchronous processing of a large amount of sequential data.
For example, in Stack Overflow: Is there really a Node.js maximum execution call limit? a large amount of data is being processed through DB calls via recursive callbacks. Eventually a Maximum call stack size exceeded error is generated.
It's possible to simplify the code through modules like Step or Flow-JS, but these still use the call stack to keep things in sync.

An interesting approach that doesn't build up the call stack is to avoid recursion and use setTimeout with a timeout value of 0 to schedule the callback call. See