// 封装
const useRet = (fn, n, time) => {
return function() {
setTimeout(async () => {
const success = await fn(...arguments);
if (success && n > 1) useRet(fn, n - 1, time)(...arguments);
}, time);
};
};
const test = () => {
return new Promise(resolve => {
resolve({ success: true });
});
};
const fn = async a => {
console.log(a); //'传一个参数'
return await test().then(({ success }) => success);
};
// 使用
const ret = useRet(fn, 5, 1000);
// 执行
ret("传一个参数");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…