Re: setTimeout only delays first time in loop



Thanks guys. I incremented the delay for each iteration and it worked.

Jim Davis wrote:

The key is going to be how you're calling that timeout. My guess is you've
put it in a loop and set 20 timeouts - think about it: of course they'd all
move at the same time (or very close) since you're setting them all at once.
;^)

I'm not sure I understand how the script is executed for it to work the
way it does. The way I figured, my original timeout said "delay 700ms,
then execute the named function (funtest)," then after funtest is
executed (which changes the position of a single li element), the
statement after the timeout is executed, which is within the same loop
of the timeout, and the loop would cause the timeout to be executed
again, causing another 700ms delay before another li changes position.

But as far as I could tell, you're saying that Javascript sees the
delay the first time, delays 700ms, then thinks "ok, I delayed 700ms
before funtest, and even if I encounter the 700ms timeout 19 more
times, that job was done so I don't have to delay again, but I still
have to execute funtest each time."

Anyone know of any online documentation for setTimeout that makes it
clear that the latter is the way it works rather than the former, or is
there a problem with my logic?

.



Relevant Pages

  • Re: trouble with timeout in event structure
    ... I am not able to run your VI since you did not include all the subVIs (checksums, temp, etc). ... otherwise you will execute the timeout a very large number of times. ... Also, you do not have a Wait ms in the while loop, so the while loop ...
    (comp.lang.labview)
  • Re: question about Timers @ stuff............
    ... setTimeout to achieve delay. ... my Internet Explorer 6 runs setTimeout() just fine. ... Setup a never ending loop that checks if Date returns a value at or ... that shall execute alert; ...
    (comp.lang.javascript)
  • Re: How to introduce delay in Structural description ?
    ... >But still the t2 instance will execute at simulation time 0ns without ... >updated the value from out1.But I dont want to execute that t2 instance ... to control an infinite loop. ... Please explain what you mean by "add delay to an instance". ...
    (comp.lang.vhdl)
  • Re: Microsecond delay in Windows?
    ... microseconds rather than, for example, milliseconds. ... possibility of recurring the delay with the same precision & accuracy!!! ... end loop ... do you need the whole loop to take a fixed amount of time to execute? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Dynamic HTML Elements Only Accessible After Alert Box?
    ... For the delay I tried both a ... timeout and just a long loop - neither seemed to do the trick. ...
    (microsoft.public.scripting.jscript)