Created
August 19, 2022 14:48
-
-
Save mjumbewu/97687f637647af343eeaf4b97c390bb8 to your computer and use it in GitHub Desktop.
A simple JavaScript function to allow using setTimeout with async/await.
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
function timeout(duration) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, duration); | |
}); | |
} | |
/* | |
Example: | |
async function dostuff() { | |
await timeout(1000); | |
// ... | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment