const LIGHT = [
{ color: 'red', delay: 2000 },
{ color: 'green', delay: 5000 },
{ color: 'yellow', delay: 3000 },
]
async function aaa() {
for (let i = 0; i <= LIGHT.length; i++) {
if (i == LIGHT.length){
aaa()
break
}
await countNum(LIGHT[i])
}
}
async function countNum(reset) {
const { color, delay } = reset
let num = delay / 1000;
for (let i = 1; i <= num; i++) {
await new Promise(resolve => {
setTimeout(() => {
resolve()
console.log('time', i)
}, 1000);
})
}
console.log('color, delay',color, delay)
}
aaa()```
```javascript
在这里插入代码片
promise红绿灯
最新推荐文章于 2024-07-24 11:09:48 发布