SOURCE

function red(){console.log('red')}
function green(){console.log('green')}
function yellow(){console.log('yellow')}
const light = (timer,cb)=>{
    return new Promise((resolve, reject)=>{
        setTimeout(()=>{
            cb()
            resolve()        
        },timer)    
    })
}
const step = ()=>{
    Promise.resolve().then(()=>{
        return light(3000, red)    
    }).then(()=>{
        return light(1000, green)    
    }).then(()=>{
        return light(2000, yellow)    
    }).then(()=>{
        return step()    
    })
}
step()
console 命令行工具 X clear

                    
>
console