MCPcopy
hub / github.com/facebook/react / workLoop

Function workLoop

packages/scheduler/src/forks/Scheduler.js:188–258  ·  view source on GitHub ↗
(initialTime: number)

Source from the content-addressed store, hash-verified

186}
187
188function 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 }

Callers 1

flushWorkFunction · 0.70

Calls 10

peekFunction · 0.90
markTaskRunFunction · 0.90
markTaskYieldFunction · 0.90
markTaskCompletedFunction · 0.90
popFunction · 0.90
advanceTimersFunction · 0.70
shouldYieldToHostFunction · 0.70
getCurrentTimeFunction · 0.70
requestHostTimeoutFunction · 0.70
callbackFunction · 0.50

Tested by

no test coverage detected