Last active
March 20, 2024 16:47
-
-
Save cowboyd/3484220151a3d4abbd63f6bc76a7bc36 to your computer and use it in GitHub Desktop.
sleep() race
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
/** | |
* Given the following definition of sleep(), how long will this program take to | |
* run? | |
* | |
* Try it out with: | |
* | |
* ``` | |
* node how-long.js | |
* ``` | |
*/ | |
async function sleep(seconds) { | |
await new Promise(resolve => setTimeout(resolve, seconds * 1000)); | |
} | |
await Promise.race([sleep(1), sleep(10)]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment