(initialTime: number)
| 186 | } |
| 187 | |
| 188 | function workLoop(initialTime: number) { |
| 189 | let currentTime = initialTime; |
| 190 | advanceTimers(currentTime); |
| 191 | currentTask = peek(taskQueue); |
| 192 | while (currentTask !== null) { |
| 193 | if (!enableAlwaysYieldScheduler) { |
| 194 | if (currentTask.expirationTime > currentTime && shouldYieldToHost()) { |
| 195 | // This currentTask hasn't expired, and we've reached the deadline. |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | // $FlowFixMe[incompatible-use] found when upgrading Flow |
| 200 | const callback = currentTask.callback; |
| 201 | if (typeof callback === 'function') { |
| 202 | // $FlowFixMe[incompatible-use] found when upgrading Flow |
| 203 | currentTask.callback = null; |
| 204 | // $FlowFixMe[incompatible-use] found when upgrading Flow |
| 205 | currentPriorityLevel = currentTask.priorityLevel; |
| 206 | // $FlowFixMe[incompatible-use] found when upgrading Flow |
| 207 | const didUserCallbackTimeout = currentTask.expirationTime <= currentTime; |
| 208 | if (enableProfiling) { |
| 209 | // $FlowFixMe[incompatible-call] found when upgrading Flow |
| 210 | markTaskRun(currentTask, currentTime); |
| 211 | } |
| 212 | const continuationCallback = callback(didUserCallbackTimeout); |
| 213 | currentTime = getCurrentTime(); |
| 214 | if (typeof continuationCallback === 'function') { |
| 215 | // If a continuation is returned, immediately yield to the main thread |
| 216 | // regardless of how much time is left in the current time slice. |
| 217 | // $FlowFixMe[incompatible-use] found when upgrading Flow |
| 218 | currentTask.callback = continuationCallback; |
| 219 | if (enableProfiling) { |
| 220 | // $FlowFixMe[incompatible-call] found when upgrading Flow |
| 221 | markTaskYield(currentTask, currentTime); |
| 222 | } |
| 223 | advanceTimers(currentTime); |
| 224 | return true; |
| 225 | } else { |
| 226 | if (enableProfiling) { |
| 227 | // $FlowFixMe[incompatible-call] found when upgrading Flow |
| 228 | markTaskCompleted(currentTask, currentTime); |
| 229 | // $FlowFixMe[incompatible-use] found when upgrading Flow |
| 230 | currentTask.isQueued = false; |
| 231 | } |
| 232 | if (currentTask === peek(taskQueue)) { |
| 233 | pop(taskQueue); |
| 234 | } |
| 235 | advanceTimers(currentTime); |
| 236 | } |
| 237 | } else { |
| 238 | pop(taskQueue); |
| 239 | } |
| 240 | currentTask = peek(taskQueue); |
| 241 | if (enableAlwaysYieldScheduler) { |
| 242 | if (currentTask === null || currentTask.expirationTime > currentTime) { |
| 243 | // This currentTask hasn't expired we yield to the browser task. |
| 244 | break; |
| 245 | } |
no test coverage detected