Skip to content

Instantly share code, notes, and snippets.

@cloverzrg
Last active March 1, 2018 03:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cloverzrg/91ee75447ab42be17c0ef7dc440a4142 to your computer and use it in GitHub Desktop.
Save cloverzrg/91ee75447ab42be17c0ef7dc440a4142 to your computer and use it in GitHub Desktop.
global.a = 0
let timer1 = setInterval(() => {
global.a++
}, 1000)
const wait = (time) => {
return new Promise((res, rej) => {
setTimeout(res, time);
})
}
const waitForAvailableProcess = async () => {
let loopCount = 0
while (1) {
loopCount++
if (global.a > 5) {
clearInterval(timer1)
break
}
console.log("loop:" + loopCount + ",a=" + global.a)
await wait(400)
}
}
waitForAvailableProcess()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment