Self correction
Name
selfCorrecting
Type
boolean
Default value
true
Description
Self correct time intervals between subsequent callback invocations to reflect actual time elapsed.
setTimeout and setInterval are not precise (explanation) which make them unusable in their basic form for functionalities that strictly depend on precise timing (like clocks, timers or time based events).
This option helps eliminating that problem by depending on absolute timestamps and auto adjusting time between each interval.
If you disable that option you will get same behaviour as using barebone setInterval but still using the advantage of control methods.
Example / Explanation
Let's say you set interval to 1000 ms. Internally it will set setTimeout(..., 1000).
But then it turns out that setTimeout actually took 1005 ms to call callback instead of 1000 ms. Now the self correction kicks in and the next setTimeout will be automatically set to 995 ms to compensate for a 5 ms drift.
This process will be repeated every interval.
But what if setTimeout take 5000 ms instead of 1005 ms? Not to worry, this case can be handled in callback by using ticks to indicate how many intervals has passed since last callback.
Last updated