// 整一个异步请求
function ajax(time) {
return new Promise((reslove) => {
setTimeout(() => {
console.log(time);
reslove(time)
}, time)
})
}
let arrList = ['ajax(1000)', 'ajax(1000)', 'ajax(1000)']
// console.log(arrList[0]);
// 异步同步器
async function* fn() {
yield ajax(1000)
yield ajax(1000)
yield ajax(1000)
}
async function test() {
for await (let val of fn()) {
console.log("start", Date.now());
console.log(val);
console.log("end", Date.now());
}
}
test()
异步遍历器一个任务结束以后执行下一个
于 2023-03-16 16:07:13 首次发布