Skip to content

Commit

Permalink
Remove catch from Scheduler build
Browse files Browse the repository at this point in the history
Makes debugging errors harder.

In this case, we can use `finally` instead.
  • Loading branch information
acdlite committed Dec 7, 2020
1 parent 30dfb86 commit 982f4c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
24 changes: 14 additions & 10 deletions packages/scheduler/src/forks/SchedulerDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,25 @@ const performWorkUntilDeadline = () => {
// the message event.
deadline = currentTime + yieldInterval;
const hasTimeRemaining = true;

// If a scheduler task throws, exit the current browser task so the
// error can be observed.
//
// Intentionally not using a try-catch, since that makes some debugging
// techniques harder. Instead, if `scheduledHostCallback` errors, then
// `hasMoreWork` will remain true, and we'll continue the work loop.
let hasMoreWork = true;
try {
const hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
if (!hasMoreWork) {
isMessageLoopRunning = false;
scheduledHostCallback = null;
} else {
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
} finally {
if (hasMoreWork) {
// If there's more work, schedule the next message event at the end
// of the preceding one.
port.postMessage(null);
} else {
isMessageLoopRunning = false;
scheduledHostCallback = null;
}
} catch (error) {
// If a scheduler task throws, exit the current browser task so the
// error can be observed.
port.postMessage(null);
throw error;
}
} else {
isMessageLoopRunning = false;
Expand Down
26 changes: 15 additions & 11 deletions packages/scheduler/src/forks/SchedulerPostTaskOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,21 +512,25 @@ const performWorkUntilDeadline = () => {
// the message event.
deadline = currentTime + yieldInterval;
const hasTimeRemaining = true;

// If a scheduler task throws, exit the current browser task so the
// error can be observed.
//
// Intentionally not using a try-catch, since that makes some debugging
// techniques harder. Instead, if `scheduledHostCallback` errors, then
// `hasMoreWork` will remain true, and we'll continue the work loop.
let hasMoreWork = true;
try {
const hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
if (!hasMoreWork) {
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
} finally {
if (hasMoreWork) {
// If there's more work, schedule the next browser task at the end of
// the preceding one.
postTask(performWorkUntilDeadline);
} else {
isTaskLoopRunning = false;
scheduledHostCallback = null;
} else {
// If there's more work, schedule the next message event at the end
// of the preceding one.
postTask(performWorkUntilDeadline);
}
} catch (error) {
// If a scheduler task throws, exit the current browser task so the
// error can be observed.
postTask(performWorkUntilDeadline);
throw error;
}
} else {
isTaskLoopRunning = false;
Expand Down

0 comments on commit 982f4c5

Please sign in to comment.