js 实现红黄绿循环打印

    // 红黄绿: 使用异步编程方案, promise, async await等都行
    // 循环打印: 一轮打印完了以后递归重复这一过程
    
    const taskRunner = (light, timeout) => {
        return new Promise((resolve) => {
            setTimeout(() => resolve(console.log(light)), timeout);
        })
    }
    const task = async () => {
        await taskRunner('红',1000)
        await taskRunner('绿',3000)
        await taskRunner('黄',2000)
        task()
    }
    
    task()
posted @ 2022-06-19 16:53  IslandZzzz  阅读(364)  评论(0编辑  收藏  举报