1. function red() {
    2. console.log('red');
    3. }
    4. function green() {
    5. console.log('green');
    6. }
    7. function yellow() {
    8. console.log('yellow');
    9. }
    10. function lightPromise(func, delay) {
    11. return new Promise((resolve, reject) => {
    12. setTimeout(() => {
    13. func();
    14. resolve();
    15. }, delay);
    16. })
    17. }
    18. function light() {
    19. Promise.resolve()
    20. .then(() => lightPromise(red, 3000))
    21. .then(() => lightPromise(green, 1000))
    22. .then(() => lightPromise(yellow, 2000))
    23. .then(light)
    24. }
    25. light();