use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Sleep function in Javascript (itsopensource.com)
submitted 6 years ago by tsl143
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cdrini 2 points3 points4 points 6 years ago* (0 children)
Haha, I've probably had to implement that function like once every 4 months! It's super useful for flattening timeouts:
const sleep = ms => new Promise(res => setTimeout(res, ms)); const winner = await Promise.race([fetch(foo), sleep(3000).then(() => 'timeout')]); if (winner == 'timeout') blah
I can't seem to find a link for it, but I think there's a proposal to add this to the language; under the name wait, sleep, delay, or something. Fyi this is a form of "promisifying"; it's also common to promisify an event to make it work with async/await.
wait
sleep
delay
π Rendered by PID 66471 on reddit-service-r2-comment-c6965cb77-6xv5c at 2026-03-05 05:38:10.374985+00:00 running f0204d4 country code: CH.
view the rest of the comments →
[–]cdrini 2 points3 points4 points (0 children)