Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Last active March 20, 2024 16:47
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 cowboyd/3484220151a3d4abbd63f6bc76a7bc36 to your computer and use it in GitHub Desktop.
Save cowboyd/3484220151a3d4abbd63f6bc76a7bc36 to your computer and use it in GitHub Desktop.
sleep() race
/**
* 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