Is it possible to implement an asynchronous loop in JavaScript without recursion?
Case in point, is it possible to synchronize a queue of asynchronous tasks without resorting to recursion? We have N asynchronous tasks in a queue, and need to execute each task after the previous one has finished.
All the examples I've seen so far use recursion for this. But if we have to deal with a very long queue, we cannot expect anything good from a recursive approach. So what's the alternative then, how to tackle this?
Just so, when a similar question was asked about promises, every single answer relies on recursion.
Your premise is wrong. As you are doing it asynchronous, there is nothing wrong with a recursive approach (sometimes dubbed pseudo-recursion), it doesn't grow the call stack.