File tree 1 file changed +11
-8
lines changed
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 1
1
import GLib from 'gi://GLib'
2
2
3
3
export class Utils {
4
- static timerId = 0
4
+ static timerIds = new Set < number > ( )
5
5
6
6
static random ( min : number , max : number ) {
7
7
return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min
@@ -12,28 +12,31 @@ export class Utils {
12
12
endFunc : ( ) => boolean ,
13
13
delayFunc : ( ) => number
14
14
) {
15
- this . timerId = GLib . timeout_add (
15
+ const timerId = GLib . timeout_add (
16
16
GLib . PRIORITY_DEFAULT ,
17
17
delayFunc ( ) ,
18
18
( ) => {
19
19
mainFunc ( )
20
20
if ( ! endFunc ( ) ) {
21
- this . _cleanupTimeout ( )
22
21
this . setInterval ( mainFunc , endFunc , delayFunc )
23
22
}
24
- this . timerId = 0
23
+ this . timerIds . delete ( timerId )
25
24
return GLib . SOURCE_REMOVE
26
25
}
27
26
)
27
+ this . timerIds . add ( timerId )
28
28
}
29
29
30
- static _cleanupTimeout ( ) {
31
- if ( this . timerId ) {
32
- GLib . Source . remove ( this . timerId )
30
+ static _cleanupTimeouts ( ) {
31
+ if ( this . timerIds . size !== 0 ) {
32
+ for ( const timerId of this . timerIds ) {
33
+ GLib . Source . remove ( timerId )
34
+ }
35
+ this . timerIds . clear ( )
33
36
}
34
37
}
35
38
36
39
static dispose ( ) {
37
- this . _cleanupTimeout ( )
40
+ this . _cleanupTimeouts ( )
38
41
}
39
42
}
You can’t perform that action at this time.
0 commit comments