Skip to content

Commit f732b86

Browse files
committed
nit: check delay > 0 in the onResume function
1 parent 2275ffb commit f732b86

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

packages/core/src/runAsync.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,41 +185,39 @@ export function scheduleProps<T>(
185185
{ key, props, state, actions }: ScheduledProps<T>
186186
): AsyncResult<T> {
187187
return new Promise((resolve, reject) => {
188-
let delay = 0
188+
let delay: number
189189
let timeout: Timeout
190190

191191
let pause = false
192192
let cancel = matchProp(props.cancel, key)
193193

194194
if (cancel) {
195-
state.cancelId = callId
196-
return onStart()
197-
}
198-
199-
pause = matchProp(props.pause, key)
200-
delay = Math.max(0, callProp(props.delay || 0, key))
201-
202-
if (delay > 0) {
195+
onStart()
196+
} else {
197+
delay = Math.max(0, callProp(props.delay || 0, key))
198+
pause = matchProp(props.pause, key)
203199
if (pause) {
204200
state.resumeQueue.add(onResume)
205201
actions.pause()
206202
} else {
207-
timeout = G.frameLoop.setTimeout(onStart, delay)
208-
state.pauseQueue.add(onPause)
203+
onResume()
209204
}
210-
} else {
211-
onStart()
212205
}
213206

214207
function onPause() {
215208
state.resumeQueue.add(onResume)
216209
timeout.cancel()
217-
delay = Math.max(0, timeout.time - G.now())
210+
// Cache the remaining delay.
211+
delay = timeout.time - G.now()
218212
}
219213

220214
function onResume() {
221-
state.pauseQueue.add(onPause)
222-
timeout = G.frameLoop.setTimeout(onStart, delay)
215+
if (delay > 0) {
216+
state.pauseQueue.add(onPause)
217+
timeout = G.frameLoop.setTimeout(onStart, delay)
218+
} else {
219+
onStart()
220+
}
223221
}
224222

225223
function onStart() {

0 commit comments

Comments
 (0)