Skip to content

Commit 899cb95

Browse files
authored
Remove unused/redundant variables from Scheduler implementation (#27130)
Tidying up some redundant code left from previous iterations of the implementation
1 parent d445cee commit 899cb95

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

packages/scheduler/src/forks/Scheduler.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function handleTimeout(currentTime: number) {
162162
}
163163
}
164164

165-
function flushWork(hasTimeRemaining: boolean, initialTime: number) {
165+
function flushWork(initialTime: number) {
166166
if (enableProfiling) {
167167
markSchedulerUnsuspended(initialTime);
168168
}
@@ -180,7 +180,7 @@ function flushWork(hasTimeRemaining: boolean, initialTime: number) {
180180
try {
181181
if (enableProfiling) {
182182
try {
183-
return workLoop(hasTimeRemaining, initialTime);
183+
return workLoop(initialTime);
184184
} catch (error) {
185185
if (currentTask !== null) {
186186
const currentTime = getCurrentTime();
@@ -193,7 +193,7 @@ function flushWork(hasTimeRemaining: boolean, initialTime: number) {
193193
}
194194
} else {
195195
// No catch in prod code path.
196-
return workLoop(hasTimeRemaining, initialTime);
196+
return workLoop(initialTime);
197197
}
198198
} finally {
199199
currentTask = null;
@@ -206,18 +206,15 @@ function flushWork(hasTimeRemaining: boolean, initialTime: number) {
206206
}
207207
}
208208

209-
function workLoop(hasTimeRemaining: boolean, initialTime: number) {
209+
function workLoop(initialTime: number) {
210210
let currentTime = initialTime;
211211
advanceTimers(currentTime);
212212
currentTask = peek(taskQueue);
213213
while (
214214
currentTask !== null &&
215215
!(enableSchedulerDebugging && isSchedulerPaused)
216216
) {
217-
if (
218-
currentTask.expirationTime > currentTime &&
219-
(!hasTimeRemaining || shouldYieldToHost())
220-
) {
217+
if (currentTask.expirationTime > currentTime && shouldYieldToHost()) {
221218
// This currentTask hasn't expired, and we've reached the deadline.
222219
break;
223220
}
@@ -465,12 +462,6 @@ function unstable_getCurrentPriorityLevel(): PriorityLevel {
465462
}
466463

467464
let isMessageLoopRunning = false;
468-
let scheduledHostCallback:
469-
| null
470-
| ((
471-
hasTimeRemaining: boolean,
472-
initialTime: DOMHighResTimeStamp | number,
473-
) => boolean) = null;
474465
let taskTimeoutID: TimeoutID = (-1: any);
475466

476467
// Scheduler periodically yields in case there is other work on the main
@@ -562,35 +553,30 @@ function forceFrameRate(fps: number) {
562553
}
563554

564555
const performWorkUntilDeadline = () => {
565-
if (scheduledHostCallback !== null) {
556+
if (isMessageLoopRunning) {
566557
const currentTime = getCurrentTime();
567558
// Keep track of the start time so we can measure how long the main thread
568559
// has been blocked.
569560
startTime = currentTime;
570-
const hasTimeRemaining = true;
571561

572562
// If a scheduler task throws, exit the current browser task so the
573563
// error can be observed.
574564
//
575565
// 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.
578568
let hasMoreWork = true;
579569
try {
580-
// $FlowFixMe[not-a-function] found when upgrading Flow
581-
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
570+
hasMoreWork = flushWork(currentTime);
582571
} finally {
583572
if (hasMoreWork) {
584573
// If there's more work, schedule the next message event at the end
585574
// of the preceding one.
586575
schedulePerformWorkUntilDeadline();
587576
} else {
588577
isMessageLoopRunning = false;
589-
scheduledHostCallback = null;
590578
}
591579
}
592-
} else {
593-
isMessageLoopRunning = false;
594580
}
595581
// Yielding to the browser will give it a chance to paint, so we can
596582
// reset this.
@@ -630,10 +616,7 @@ if (typeof localSetImmediate === 'function') {
630616
};
631617
}
632618

633-
function requestHostCallback(
634-
callback: (hasTimeRemaining: boolean, initialTime: number) => boolean,
635-
) {
636-
scheduledHostCallback = callback;
619+
function requestHostCallback(callback: (initialTime: number) => boolean) {
637620
if (!isMessageLoopRunning) {
638621
isMessageLoopRunning = true;
639622
schedulePerformWorkUntilDeadline();

0 commit comments

Comments
 (0)