美文网首页
使用async & await & Promise 实现队列任务

使用async & await & Promise 实现队列任务

作者: 老夫当年也是神一般的少年 | 来源:发表于2020-08-19 10:16 被阅读0次

let tmp = [];
(
async () => {
for (let i = 1; i < 11; i++) {
await new Promise((resolve, reject) => {
setTimeout(() => {
tmp.push(i);
console.log('第' + i + '条记录');
if (i === 10) {
console.log('tmp', tmp)
} else {
resolve()
}
}, Math.ceil(Math.random()*100));
})
}
}
)()

相关文章

网友评论

      本文标题:使用async & await & Promise 实现队列任务

      本文链接:https://www.haomeiwen.com/subject/afrrjktx.html