异步迭代器for-await-for的使用
const Time = (time)=> {
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve(time)
},time)
})
}
async function text(){
let arr = [Time(2000),Time(1000),Time(3000)]
// arr.map(async ele=>{
// let result = await ele
// console.log(result) // 1000 2000 300
// })
for await (let i of arr){ // for of同步的
console.log(i) // 2000 1000 3000
}
}
text()