Skip to content

Instantly share code, notes, and snippets.

@valterlobo
Last active July 1, 2022 00:56
Show Gist options
  • Save valterlobo/fe65ee3e2252cd653c43fcddcb6b6fe8 to your computer and use it in GitHub Desktop.
Save valterlobo/fe65ee3e2252cd653c43fcddcb6b6fe8 to your computer and use it in GitHub Desktop.
javascript sleep async
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