Skip to content

Instantly share code, notes, and snippets.

@htdat
Created May 19, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htdat/a6ae2d7e3d763aff61fc1f1ede4d2d1e to your computer and use it in GitHub Desktop.
Save htdat/a6ae2d7e3d763aff61fc1f1ede4d2d1e to your computer and use it in GitHub Desktop.
Timeout for Promise in JavaScript
// Definition - wait X seconds
const wait = seconds => new Promise(resolve => setTimeout(resolve, 1000 * seconds));
/* Usage */
async functionA() {
// Do something
// ...
// Wait for 10 seconds
await wait(10);
// Do something else
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment