其他分享
首页 > 其他分享> > for await of用法

for await of用法

作者:互联网

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

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

test()
// 1560092345730 2000
// 1560092345730 100
// 1560092346336 3000

标签:function,arr,await,用法,1560092345730,3000,time,Gen
来源: https://blog.csdn.net/qq_45305088/article/details/123129927