summaryrefslogtreecommitdiff
path: root/timers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'timers.ts')
-rw-r--r--timers.ts37
1 files changed, 17 insertions, 20 deletions
diff --git a/timers.ts b/timers.ts
index a5caf94d8..42e5a6cb6 100644
--- a/timers.ts
+++ b/timers.ts
@@ -39,15 +39,16 @@ function onMessage(payload: Uint8Array) {
}
}
-export function setTimeout(
+function setTimer(
cb: TimerCallback,
duration: number,
+ interval: boolean,
// tslint:disable-next-line:no-any
- ...args: any[]
+ args: any[]
): number {
const timer = {
id: nextTimerId++,
- interval: false,
+ interval,
duration,
args,
cb
@@ -56,34 +57,28 @@ export function setTimeout(
dispatch.sendMsg("timers", {
command: pb.Msg.Command.TIMER_START,
timerStartId: timer.id,
- timerStartInterval: false,
+ timerStartInterval: interval,
timerStartDuration: duration
});
return timer.id;
}
-// TODO DRY with setTimeout
+export function setTimeout(
+ cb: TimerCallback,
+ duration: number,
+ // tslint:disable-next-line:no-any
+ ...args: any[]
+): number {
+ return setTimer(cb, duration, false, args);
+}
+
export function setInterval(
cb: TimerCallback,
repeat: number,
// tslint:disable-next-line:no-any
...args: any[]
): number {
- const timer = {
- id: nextTimerId++,
- interval: true,
- duration: repeat,
- args,
- cb
- };
- timers.set(timer.id, timer);
- dispatch.sendMsg("timers", {
- command: pb.Msg.Command.TIMER_START,
- timerStartId: timer.id,
- timerStartInterval: true,
- timerStartDuration: repeat
- });
- return timer.id;
+ return setTimer(cb, duration, true, args);
}
export function clearTimer(id: number) {
@@ -92,3 +87,5 @@ export function clearTimer(id: number) {
timerClearId: id
});
}
+
+