ES9中的for await of

2019-11-11 张宇童 学习日志

function Gen(time) {
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            resolve(time)
        },time)
    })
} 

async function test() {
    let arr = [Gen(2000), Gen(200), Gen(3000)]
    for(let i of arr) {
        console.log(Date.now())
        console.log(Date.now(), await i.then(console.log))
        console.log(Date.now())
    }
}

test().then(() => {console.log('<<<======华丽分割线======>>>'); testTwo()})

async function testTwo() {
    let arr = [Gen(3000), Gen(300), Gen(2000)]
    for await (let i of arr) {
        console.log(Date.now(), i)
    }
}



屏幕快照 2019-11-11 下午10.39.56.png

标签: javascript ES6

发表评论:

Powered by emlog