File tree 1 file changed +15
-11
lines changed
1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -13,13 +13,15 @@ function onTimeout () {
13
13
while ( idx < len ) {
14
14
const timer = fastTimers [ idx ]
15
15
16
- if ( timer . expires && fastNow >= timer . expires ) {
17
- timer . expires = 0
16
+ if ( timer . state === 0 ) {
17
+ timer . state = fastNow + timer . delay
18
+ } else if ( timer . state >= 0 && fastNow >= timer . state ) {
19
+ timer . state = - 1
18
20
timer . callback ( timer . opaque )
19
21
}
20
22
21
- if ( timer . expires === 0 ) {
22
- timer . active = false
23
+ if ( timer . state === - 1 ) {
24
+ timer . state = - 2
23
25
if ( idx !== len - 1 ) {
24
26
fastTimers [ idx ] = fastTimers . pop ( )
25
27
} else {
@@ -53,27 +55,29 @@ class Timeout {
53
55
this . callback = callback
54
56
this . delay = delay
55
57
this . opaque = opaque
56
- this . expires = 0
57
- this . active = false
58
+
59
+ // -2 not in timer list
60
+ // -1 in timer list but inactive
61
+ // 0 in timer list waiting for time
62
+ // > 0 in timer list waiting for time to expire
63
+ this . state = - 2
58
64
59
65
this . refresh ( )
60
66
}
61
67
62
68
refresh ( ) {
63
- if ( ! this . active ) {
64
- this . active = true
69
+ if ( this . state === - 2 ) {
65
70
fastTimers . push ( this )
66
71
if ( ! fastNowTimeout || fastTimers . length === 1 ) {
67
72
refreshTimeout ( )
68
- fastNow = Date . now ( )
69
73
}
70
74
}
71
75
72
- this . expires = fastNow + this . delay
76
+ this . state = 0
73
77
}
74
78
75
79
clear ( ) {
76
- this . expires = 0
80
+ this . state = - 1
77
81
}
78
82
}
79
83
You can’t perform that action at this time.
0 commit comments