Skip to content

Instantly share code, notes, and snippets.

@BlairCurrey
Created June 6, 2023 11:24
Show Gist options
  • Save BlairCurrey/241e1a6534efc7810c3f389fd79d93de to your computer and use it in GitHub Desktop.
Save BlairCurrey/241e1a6534efc7810c3f389fd79d93de to your computer and use it in GitHub Desktop.
wait utility function for js
// 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