Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

48.红绿灯算法 #48

Open
webVueBlog opened this issue Aug 22, 2022 · 0 comments
Open

48.红绿灯算法 #48

webVueBlog opened this issue Aug 22, 2022 · 0 comments

Comments

@webVueBlog
Copy link
Member

/*
 * description  : 红绿灯算法
 */

// 有黄绿红,他们各自亮灯的持续时间是 1s,2s,3s 如此反复。
// 还有暂停开始之类的功能:

function timePromise(time) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, time)
  })
}
async function setColor(i, color) {
  console.log('设置颜色', color)
  await timePromise(i)
}

async function run() {
  // 这里用了while循环 递归也可以
  while (true) {
    await setColor(3000, 'red')
    await setColor(2000, 'green')
    await setColor(1000, 'yellow')
  }
}

run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant