What's going on, please, and why?
I'll have a crack at answering this. Its easier to understand when you simplify it down to psuedo-code:
So, this is what is happening:while set $time to current time test $time < $expiry fail: break loop test $time - $prevtime >= 10 fail: sleep 10 $prevtime = $time warn $time
You can clearly see the pattern of sleep, no sleep, sleep, no sleep. Essentially the even iterations are doing the 2nd iteration and odd iterations are doing the 3rd iteration (just advancing numbers in each case).$expiry = 3600 $prevtime = undef $time = undef 1st loop: $time = 123 $time 123 < $expiry 3600 (true) $time 123 - $prevtime undef >= 10 (true) $prevtime = 123 warn $time 123 2nd loop: $time = 123 (first iteration takes less than 1 second) $time 123 < $expiry 3600 (true) $time 123 - $prevtime 123 >= 10 (false) sleep 10 $prevtime = 123 warn $time 123 3rd loop: $time = 133 (slept on last iteration so advance 10s) $time 133 < $expiry 3600 (true) $time 133 - $prevtime 123 >= 10 (true) $prevtime = 133 warn $time 133 4th loop: $time = 133 (last iteration took less than 1s) ...
That is what is happening. Why it is happening is because you set a fixed point in time and then use current time to compare it, mixing in a bit of sleeping as well. This effectively shifts your processing from working in the now to working in the past (or future, depending on your perspective) and then updating to work on the now again for the next loop (but still comparing your now value to the previous past value).
In reply to Re: while loop acting up, though I'm not sure how
by SimonPratt
in thread while loop acting up, though I'm not sure how
by msh210
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |