You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current behaviour for setInterval is to wait the defined time and then execute the function, until the interval is cleared. Since setInterval is the primary function for periodic events, it might be a good idea to add an option to execute the function immediately instead of first waiting for the defined timeout.
For example, a LED could be set to blink using setInterval, where the option would determine if you want the LED to blink immediately or only after the first timeout occurred.
The text was updated successfully, but these errors were encountered:
This should really be a bug report for in Espruino.
But: While I can see it would be useful, I'm not sure:
setInterval(foo, 60000, { execNow : true });
is really any more obvious than:
setInterval(foo, 60000);
foo();
or:
setInterval(foo, 60000);
setTimeout(foo, 1);
I just don't think it's a good idea - mainly because setInterval is something that's used all over the place and is basically a standard (web browsers, node, etc) and changing the behaviour would be bad news.
I leave this one up to you. Another option would be to introduce a new function that just wraps the setInterval and the direct execution in one. I have used this construct a lot so far, so I would argue that it is a fairly typical use case.
Sorry - I'm going to close this one. Nobody else has had problems with the old implementation, and you could easily just write the following at the top of your code:
function setIntervalNow(a,b,c) {
a();
return setInterval(a,b,c);
}
The current behaviour for setInterval is to wait the defined time and then execute the function, until the interval is cleared. Since setInterval is the primary function for periodic events, it might be a good idea to add an option to execute the function immediately instead of first waiting for the defined timeout.
For example, a LED could be set to blink using setInterval, where the option would determine if you want the LED to blink immediately or only after the first timeout occurred.
The text was updated successfully, but these errors were encountered: