Skip to content

Instantly share code, notes, and snippets.

@Quickz
Created June 30, 2020 14:44
Show Gist options
  • Save Quickz/325707653eda735839713a99eae1cf96 to your computer and use it in GitHub Desktop.
Save Quickz/325707653eda735839713a99eae1cf96 to your computer and use it in GitHub Desktop.
Asynchronous loop with a delay between iterations
doStuff();
async function doStuff()
{
while (true)
{
console.log("Hello, world!");
await sleep(500);
}
}
function sleep(milliseconds: number)
{
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment