es9语法:for await of 的用法

Posted on 2020-10-01 23:24  猫头唔食鱼  阅读(2466)  评论(0编辑  收藏  举报
 function getTime(seconds){
            return new Promise(resolve=>{
                setTimeout(() => {
                    resolve(seconds)
                }, seconds);
            })
        }

         

        async function test(){
            let arr = [getTime(2000),getTime(300),getTime(1000)]
            for await (let x of arr){
                console.log(x); // 2000  300 1000 按顺序的
            }
         }

        test()