Remove unused/redundant variables from Scheduler implementation (#27130)
Tidying up some redundant code left from previous iterations of the implementation
Andrew Clark committed
Jul 19, 2023 at 14:29 UTC
899cb95f52cc83ab5ca1eb1e268c909d3f0961e7
1 file changed
+10
-27
packages/scheduler/src/forks/Scheduler.js
+10
-27
@@ -162,7 +162,7 @@ function handleTimeout(currentTime: number) {
162
}
163
}
164
165
-function flushWork(hasTimeRemaining: boolean, initialTime: number) {
165
+function flushWork(initialTime: number) {
166
if (enableProfiling) {
167
markSchedulerUnsuspended(initialTime);
168
}
@@ -180,7 +180,7 @@ function flushWork(hasTimeRemaining: boolean, initialTime: number) {
180
try {
181
if (enableProfiling) {
182
try {
183
- return workLoop(hasTimeRemaining, initialTime);
183
+ return workLoop(initialTime);
184
} catch (error) {
185
if (currentTask !== null) {
186
const currentTime = getCurrentTime();
@@ -193,7 +193,7 @@ function flushWork(hasTimeRemaining: boolean, initialTime: number) {
193
}
194
} else {
195
// No catch in prod code path.
196
- return workLoop(hasTimeRemaining, initialTime);
196
+ return workLoop(initialTime);
197
}
198
} finally {
199
currentTask = null;
@@ -206,7 +206,7 @@ function flushWork(hasTimeRemaining: boolean, initialTime: number) {
206
}
207
}
208
209
-function workLoop(hasTimeRemaining: boolean, initialTime: number) {
209
+function workLoop(initialTime: number) {
210
let currentTime = initialTime;
211
advanceTimers(currentTime);
212
currentTask = peek(taskQueue);
@@ -214,10 +214,7 @@ function workLoop(hasTimeRemaining: boolean, initialTime: number) {
214
currentTask !== null &&
215
!(enableSchedulerDebugging && isSchedulerPaused)
216
) {
217
- if (
218
- currentTask.expirationTime > currentTime &&
219
- (!hasTimeRemaining || shouldYieldToHost())
220
- ) {
217
+ if (currentTask.expirationTime > currentTime && shouldYieldToHost()) {
218
// This currentTask hasn't expired, and we've reached the deadline.
219
break;
220
}
@@ -465,12 +462,6 @@ function unstable_getCurrentPriorityLevel(): PriorityLevel {
462
}
463
464
let isMessageLoopRunning = false;
468
-let scheduledHostCallback:
469
- | null
470
- | ((
471
- hasTimeRemaining: boolean,
472
- initialTime: DOMHighResTimeStamp | number,
473
- ) => boolean) = null;
465
let taskTimeoutID: TimeoutID = (-1: any);
466
467
// Scheduler periodically yields in case there is other work on the main
@@ -562,23 +553,21 @@ function forceFrameRate(fps: number) {
553
}
554
555
const performWorkUntilDeadline = () => {
565
- if (scheduledHostCallback !== null) {
556
+ if (isMessageLoopRunning) {
557
const currentTime = getCurrentTime();
558
// Keep track of the start time so we can measure how long the main thread
559
// has been blocked.
560
startTime = currentTime;
570
- const hasTimeRemaining = true;
561
562
// If a scheduler task throws, exit the current browser task so the
563
// error can be observed.
564
//
565
// Intentionally not using a try-catch, since that makes some debugging
576
- // techniques harder. Instead, if `scheduledHostCallback` errors, then
577
- // `hasMoreWork` will remain true, and we'll continue the work loop.
566
+ // techniques harder. Instead, if `flushWork` errors, then `hasMoreWork` will
567
+ // remain true, and we'll continue the work loop.
568
let hasMoreWork = true;
569
try {
580
- // $FlowFixMe[not-a-function] found when upgrading Flow
581
- hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
570
+ hasMoreWork = flushWork(currentTime);
571
} finally {
572
if (hasMoreWork) {
573
// If there's more work, schedule the next message event at the end
@@ -586,11 +575,8 @@ const performWorkUntilDeadline = () => {
575
schedulePerformWorkUntilDeadline();
576
} else {
577
isMessageLoopRunning = false;
589
- scheduledHostCallback = null;
578
}
579
}
592
- } else {
593
- isMessageLoopRunning = false;
580
}
581
// Yielding to the browser will give it a chance to paint, so we can
582
// reset this.
@@ -630,10 +616,7 @@ if (typeof localSetImmediate === 'function') {
616
};
617
}
618
633
-function requestHostCallback(
634
- callback: (hasTimeRemaining: boolean, initialTime: number) => boolean,
635
-) {
636
- scheduledHostCallback = callback;
619
+function requestHostCallback(callback: (initialTime: number) => boolean) {
620
if (!isMessageLoopRunning) {
621
isMessageLoopRunning = true;
622
schedulePerformWorkUntilDeadline();