clearInterval is killing setTimeout #1455
Replies: 11 comments
-
Posted at 2016-11-26 by Wilberforce https://www.espruino.com/Reference#l__global_clearInterval If no argument is supplied, all timers and intervals are stopped So it is doing what is says on the box... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by Cale ugh... I just seen that. ok |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by Cale under else if statement: Still clearing the setTimeout even though it is run after clearInterval
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by Cale Here is an example that causes errors...
And this is the error:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by @gfwilliams You shouldn't really use just What you're doing is you're clearing all timeouts - including the one that was set up inside the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by Cale Ok got it. Thank you |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by @allObjects
@gfwilliams, I guess you wanted to say ...without arguments. And even on initialization it could interfere with something that should survive an Therefore, best practices are:
Code in level 0 (or root level) is executed by Espruino at upload time (see Simple explanation how to save code that Espruino runs on start?). Even if the intervals or timeouts are embedded a function but that function is - directly or indirectly - called in level 0 (after its definition), those intervals and timeouts get set on upload. Unpredictable behavior and weird side effects are usually the result when saving code that has already began running. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-27 by @gfwilliams Just added - thanks :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-22 by Sigma I got an error :
Does the code have some mistakes ? Help, thx! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-22 by @gfwilliams The only problem you have is that when the If you did:
it would probably fix it? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-04-13 by Sigma I use timer to flag if action be done. Resolved. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-26 by Cale
Shouldn't the following code output (from console.log()) onInit, foo, bar ?? Instead on onInit, foo ??
It seems that clearInterval is killing the setTimeout? That's not normal is it?
I'm on PICO:
Beta Was this translation helpful? Give feedback.
All reactions