Skip to content Skip to sidebar Skip to footer

How Should I Loop Through Asynchronous Functions That Rely On The Previous Loop's Value?

The synchronous version (simplified for readability) of what I'm trying to do in node.js: var value = null; var allValues = []; do{ value = getValue(value); //load the next value

Solution 1:

I'll hit a stack limit

No, you won't. If they're really asynchronous, then the next call to iteratGetValue will be in a new stack frame - originating in the top-level execution context of the async callback handler. It's the same for Promises - some of which are even required to be asynchronous.

Post a Comment for "How Should I Loop Through Asynchronous Functions That Rely On The Previous Loop's Value?"