diff options
Diffstat (limited to 'subprojects/frontend/src/utils/Timer.ts')
-rw-r--r-- | subprojects/frontend/src/utils/Timer.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/subprojects/frontend/src/utils/Timer.ts b/subprojects/frontend/src/utils/Timer.ts index 14e9eb81..4bb1bb9c 100644 --- a/subprojects/frontend/src/utils/Timer.ts +++ b/subprojects/frontend/src/utils/Timer.ts | |||
@@ -1,33 +1,33 @@ | |||
1 | export default class Timer { | 1 | export default class Timer { |
2 | readonly callback: () => void; | 2 | private readonly callback: () => void; |
3 | 3 | ||
4 | readonly defaultTimeout: number; | 4 | private readonly defaultTimeout: number; |
5 | 5 | ||
6 | timeout: number | null = null; | 6 | private timeout: number | undefined; |
7 | 7 | ||
8 | constructor(callback: () => void, defaultTimeout = 0) { | 8 | constructor(callback: () => void, defaultTimeout = 0) { |
9 | this.callback = () => { | 9 | this.callback = () => { |
10 | this.timeout = null; | 10 | this.timeout = undefined; |
11 | callback(); | 11 | callback(); |
12 | }; | 12 | }; |
13 | this.defaultTimeout = defaultTimeout; | 13 | this.defaultTimeout = defaultTimeout; |
14 | } | 14 | } |
15 | 15 | ||
16 | schedule(timeout: number | null = null): void { | 16 | schedule(timeout?: number | undefined): void { |
17 | if (this.timeout === null) { | 17 | if (this.timeout === undefined) { |
18 | this.timeout = setTimeout(this.callback, timeout || this.defaultTimeout); | 18 | this.timeout = setTimeout(this.callback, timeout ?? this.defaultTimeout); |
19 | } | 19 | } |
20 | } | 20 | } |
21 | 21 | ||
22 | reschedule(timeout: number | null = null): void { | 22 | reschedule(timeout?: number | undefined): void { |
23 | this.cancel(); | 23 | this.cancel(); |
24 | this.schedule(timeout); | 24 | this.schedule(timeout); |
25 | } | 25 | } |
26 | 26 | ||
27 | cancel(): void { | 27 | cancel(): void { |
28 | if (this.timeout !== null) { | 28 | if (this.timeout !== undefined) { |
29 | clearTimeout(this.timeout); | 29 | clearTimeout(this.timeout); |
30 | this.timeout = null; | 30 | this.timeout = undefined; |
31 | } | 31 | } |
32 | } | 32 | } |
33 | } | 33 | } |