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

Function workLoop

packages/scheduler/src/forks/SchedulerMock.js:188–261  ·  view source on GitHub ↗
(hasTimeRemaining: boolean, initialTime: number)

Source from the content-addressed store, hash-verified

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