Created
November 21, 2023 05:51
-
-
Save gh640/40f9eb5b5dc8fca3e3abf12fc804bedd to your computer and use it in GitHub Desktop.
JavaScript: async `waitFor` function
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
/** | |
* Wait for the specified milliseconds. | |
*/ | |
async function waitFor(msec) { | |
await new Promise((resolve) => setTimeout(resolve, msec)); | |
} |
Usage:
// Wait 1000 milliseconds.
await waitFor(1000);
// Wait 3000 milliseconds and print out.
waitFor(3000).then(() => console.log("3 seconds."));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Different declaration with the similar behavior: