promise 递归

let counter = 0;
const max = 5;
function promise () {
console.log(waiting ${counter ++}s...);
return new Promise(resolve => {
if (counter >= max) {
return resolve(“promise finish”);
} else {
setTimeout(() => {
promise().then(res => resolve(res));
}, 1000);
}
})}

promise()
.then(res => {
console.log(res)
})

猜你喜欢

转载自blog.csdn.net/u012540058/article/details/83987814