Created
June 6, 2023 11:24
-
-
Save BlairCurrey/241e1a6534efc7810c3f389fd79d93de to your computer and use it in GitHub Desktop.
wait utility function for js
This file contains hidden or 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
// Prevents have to do a callback in setTimeout | |
function wait(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
// no top level await :/ | |
async function someAsyncFunction() { | |
await wait(1000); // Wait for 1 second | |
} | |
someAsyncFunction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment