-
-
Save valterlobo/fe65ee3e2252cd653c43fcddcb6b6fe8 to your computer and use it in GitHub Desktop.
javascript sleep async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function main() { | |
async function bot(cod) { | |
console.log("START BOOT:", cod); | |
let i = 0; | |
while (i < 10000) { | |
i++; | |
} | |
console.log("END BOOT:", cod); | |
} | |
function sleep(ms) { | |
console.log("SLEEP:", ms); | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms); | |
}); | |
} | |
let cod = 0; | |
while (true) { | |
console.log("RESTART ............."); | |
cod = cod + 1; | |
await bot(cod); | |
await sleep(1000); | |
} | |
} | |
main().catch((error) => { | |
console.error(error); | |
process.exitCode = 1; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment