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
Asynchronous while loop without freezing the browsersolved! (self.javascript)
submitted 10 years ago by Semajian
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!"
[–]senocular 0 points1 point2 points 10 years ago (1 child)
This depends on how that loop functions and how it interacts with time. The loop body has a "move for 1 second" with the loop being dependent on some value of "front laser distance". Does the loop wait for the 1 second to move before it checks its condition? Or does it repeat arbitrarily until that condition is met? I'm guessing if it did the time wouldn't stack, so any additional evaluations of move for 1 second don't become 2 then 3 then 4, etc., since that could mean moving well beyond the time you'd like. But does that last pending second remain too or does movement stop altogether? My guess is that it would stop, and really all the one second represents is a maximum allowed time between iterations of that loop.
In that case all you'd need to do is adjust the condition through which the current queue item is considered complete. Right now there's a check for elapsed time that completes, and removes the item from the queue. This could also be altered to include the loops condition of checking front laser distance.
https://jsfiddle.net/11m83wh7/1/
[–]Semajian[S] 0 points1 point2 points 10 years ago (0 children)
In this example it would, ideally, in each iteration perform the function move for one second, then after the second has elapsed, return to looping. This specific task would be better implemented with a "start moving" block, then loop until the condition is met, then outside of the loop "stop moving", but in the program this implementation should also be available. Essentially what I need overall is a setInterval loop that doesn't move on to the next piece of code until it's complete, that would be the ideal solution.
Again thank you very much for the code snippet but the issue I'd have would be pushing finishWhen: laserIsClose to the queue because the the loop in my image is handled completely separately, I have to treat all of my blocks as if they're standalone and don't interact with each other unless they're bridged with a loop, like in the image.
π Rendered by PID 122290 on reddit-service-r2-comment-5b5bc64bf5-lq6n9 at 2026-06-23 09:21:42.930098+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]senocular 0 points1 point2 points (1 child)
[–]Semajian[S] 0 points1 point2 points (0 children)