【发布时间】:2019-05-27 16:00:12
【问题描述】:
我有这个异步块:
test().then(function(result){
// Success: Do something.
doSomething();
}).catch(function(error){
// Error: Handle the error, retry!
// How to re-run this whole block?
});
我可以跟踪success 和failed 结果。但是,如果我们失败了,是否可以重试整个test().then().catch() 链?并继续重试直到条件解决?
【问题讨论】:
-
把它放在一个函数中。调用它。
-
请注意,您应该限制重试的频率,甚至是退避延迟,这样您就不会陷入无限循环并可能会耗尽
test或 @ 中的任何资源987654327@ 失败。 -
喜欢,使用
setTimeout()?
标签: javascript node.js asynchronous promise