我正在尝试编写一个简单的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);我可以认为它只是递归吗? 有超载堆栈问题?如果是的话,有什么模式可以避免递归?