备忘录
原来的:
加上async await
网上抄来的示例改了一下下:
let outer = ['out1','out2','out3'],inner = ['in1','in2','in3'];
async function runTask(){
const timeout = ()=>{
//关键是promise
return new Promise(res=>{
setTimeout(()=>{
res()
},2000)
})
}
console.log('任务开始')
for (let index = 0; index < outer.length; index++) {
const o = outer[index];
for (let index = 0; index < inner.length; index++) {
const i = inner[index];
await timeout(i)
console.log(`inner里的${i}完成`)
}
}}
console.log('任务完成')
runTask()
修改后: