Skip to content

Commit 6950837

Browse files
committed
2 parents 1b37449 + 63c1a19 commit 6950837

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/system/timer.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "./event.js";
99
import state from "../state/state.js";
1010
import { clamp } from "../math/math.js";
11+
import { defer } from "./../utils/function.js";
1112

1213
/**
1314
* a Timer class to manage timing related function (FPS, Game Tick, Time...)
@@ -182,6 +183,30 @@ class Timer {
182183
return this.timerId;
183184
}
184185

186+
/**
187+
* Cancels a timeout previously established by calling setTimeout().
188+
* @param timeoutID - ID of the timeout to be cancelled
189+
*/
190+
clearTimeout(timeoutID: number) {
191+
if (timeoutID > 0) {
192+
defer(() => {
193+
this.clearTimer(timeoutID);
194+
}, this);
195+
}
196+
}
197+
198+
/**
199+
* cancels the timed, repeating action which was previously established by a call to setInterval().
200+
* @param intervalID - ID of the interval to be cleared
201+
*/
202+
clearInterval(intervalID: number) {
203+
if (intervalID > 0) {
204+
defer(() => {
205+
this.clearTimer(intervalID);
206+
}, this);
207+
}
208+
}
209+
185210
/**
186211
* Return the current timestamp in milliseconds <br>
187212
* since the game has started or since linux epoch (based on browser support for High Resolution Timer)

0 commit comments

Comments
 (0)