const showLight = ({color, delay} = {color: 'red', delay: 1000}) => {
return new Promise(resolve => {
console.log(color)
const timer = setTimeout(resolve, delay)
})
}
async function showLights(lights) {
while(lights.length) {
const curLight = lights.pop()
await showLight(curLight)
lights.unshift(curLight)
}
// await showLight()
// await showLight({color: 'yellow', delay: 1000})
// await showLight({color: 'green', delay: 1000})
// showLights(lights)
}
showLights([{color: 'yellow', delay: 1000}, {color: 'green', delay: 1000}])
console