-
Notifications
You must be signed in to change notification settings - Fork 699
Open
Description
I'm submitting a ...
[X] bug report
Steps to reproduce the bug:
It's a countdown timer bug. Timer is using setTimeout
function repeatedly from recursive function without checking if timeout was previously set. So if user inadvertently calls timerTick
several times, for example, by quickly alternating between calls to resumeTimer
and pauseTimer
, he can set several timeouts running in parallel, resulting in an incorrect timer.
Related code:
It can be fixed in several ways, for example, current function
timerTick() {
setTimeout(() => {
...
});
}
can be changed into something like
timerTick() {
// this._timeoutHandle is null by default, so if it is not null now, means setTimeout()
// was previously called, and is now either executing or preparing to execute.
// By calling clearTimeout() in such case, we prevent another timerTick call chain
// running in another timeout callback.
if (this._timeoutHandle != null) {
clearTimeout(this._timeoutHandle);
this._timeoutHandle = null;
}
this._timeoutHandle = setTimeout(() => {
...
});
kaiquecruz
Metadata
Metadata
Assignees
Labels
No labels