延时顺序打印

        const myPromise = num=>{
            return new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    resolve(num)
                },1000)
            })
        }

        async function test(){
            for(let i = 0;i<5;){
                i++
                console.log(await myPromise(i));
            }
        }

        test()

 

posted @ 2021-06-09 18:41  珂珂keo  阅读(39)  评论(0编辑  收藏  举报