Created
May 19, 2020 16:18
-
-
Save htdat/a6ae2d7e3d763aff61fc1f1ede4d2d1e to your computer and use it in GitHub Desktop.
Timeout for Promise in JavaScript
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
// 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