SOURCE

function red() {
    console.log('red');
}
function green() {
    console.log('green');
}
function yellow() {
    console.log('yellow');
}

let light = (timer, fn) => new Promise((resolve, reject) => {
    setTimeout(() => {
        fn();
        resolve();
    }, timer);
});

let start = () => {
    light(3000, red).then(() => {
        return light(1000, green);
    }).then(() => {
        return light(2000, yellow);
    }).then(() =>{
        start();
    })
}

start();
console 命令行工具 X clear

                    
>
console