如果我具有如下所示的递归函数怎么办?我可以在递归foo
调用之后返回false吗?
function foo(fn, redo, interval = 1000) {
return new Promise(
(resolve, reject) => {
fn()
.then(resolve)
.catch((error) => {
setTimeout(() => {
if (redo === 1) {
reject(error);
const unusedComponent = () => null;
return unusedComponent;
}
foo(fn, retriesLeft - 1, interval).then(resolve, reject);
}, interval);
return null;
});
}
);
}
答案 0 :(得分:0)
通过在foo上添加return来返回递归调用