关于带有promise的javascript中的重试模式和递归

时间:2017-05-10 06:52:32

标签: javascript recursion promise

我正在尝试编写一个简单的retry-promise模式,以解决ajax请求中的泛型重试问题...现在我发现这个源代码运行良好

 function keepTrying(otherArgs, promise) {
    promise = promise||new Promise();

    // try doing the important thing

    if(success) {
        promise.resolve(result);
    } else {
        setTimeout(function() {
            keepTrying(otherArgs, promise);
        }, retryInterval);
    }
}

与此类似,此链接https://gist.github.com/briancavalier/842626

还有更多示例

但我的问题是: 如果我叫keepTrying(otherArgs,promise);我可以认为它只是递归吗? 有超载堆栈问题?如果是的话,有什么模式可以避免递归?

0 个答案:

没有答案