Last active
March 28, 2024 19:58
-
-
Save nichoth/9764e87f843f8a0cd7f5682ae6a3e526 to your computer and use it in GitHub Desktop.
Async sleep — return a promise that waits for ms
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
/** | |
* Sleeps for `ms` milliseconds. | |
* @param {number} ms | |
* @return {Promise} | |
*/ | |
async function sleep (ms:number) { | |
await new Promise((resolve) => { | |
if (!ms) { | |
process.nextTick(resolve) | |
} else { | |
setTimeout(resolve, ms) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment