Skip to content

Instantly share code, notes, and snippets.

@stekhn
Created July 29, 2020 12:53
Show Gist options
  • Save stekhn/95c4710356c1949b838ebbfcf138dbd5 to your computer and use it in GitHub Desktop.
Save stekhn/95c4710356c1949b838ebbfcf138dbd5 to your computer and use it in GitHub Desktop.
Asynchronous sleep function for JavaScript, similar to Python. Also known as a wait or delay function
async function sleep(milliseconds) {
return new Promise(resolve => {
setTimeout(() => {
resolve(true);
}, milliseconds);
});
}
// await sleep(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment