异步循环,不递归? [英] Asynchronous loop without recursion?
问题描述
是否有可能实现在JavaScript中的异步循环,不递归?
典型的例子,是有可能,而不诉诸递归的异步任务队列进行同步?我们在一个队列ñ异步任务,并且需要previous一个人完成后执行每个任务。
我到目前为止看到使用递归这种情况的例子。但是,如果我们要处理一个很长的队列中,我们不能指望任何来自递归的方法好。那么,有什么替代的话,怎么解决呢?
正是如此,当一个类似的问题被问及承诺,每一个答案依赖于递归。
我们不能指望从递归的方法什么好东西。
块引用>您premise是错误的。当你正在异步这样做,有什么不对的递归方法(有时也被称为伪递归),这不是' ŧ增长调用堆栈。
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.
解决方案we cannot expect anything good from a recursive approach.
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.
这篇关于异步循环,不递归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!