Extract task execution to a separate method in RuntimeScheduler (#37881)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37881

Small refactor in preparation to add systrace markers for several methods in RuntimeScheduler.

Changelog: [internal]

Reviewed By: rshest

Differential Revision: D46556398

fbshipit-source-id: a0b92ea9173a55ec5a845bcfa278018ec3349e1f
This commit is contained in:
Rubén Norte
2023-09-19 09:03:33 -07:00
committed by Facebook GitHub Bot
parent 8b768f144a
commit b38a9dedd3
2 changed files with 23 additions and 22 deletions
@@ -106,17 +106,7 @@ void RuntimeScheduler::callExpiredTasks(jsi::Runtime& runtime) {
break;
}
currentPriority_ = topPriorityTask->priority;
auto result = topPriorityTask->execute(runtime, didUserCallbackTimeout);
if (result.isObject() && result.getObject(runtime).isFunction(runtime)) {
topPriorityTask->callback =
result.getObject(runtime).getFunction(runtime);
} else {
if (taskQueue_.top() == topPriorityTask) {
taskQueue_.pop();
}
}
executeTask(runtime, topPriorityTask, didUserCallbackTimeout);
}
} catch (jsi::JSError& error) {
handleFatalError(runtime, error);
@@ -151,17 +141,7 @@ void RuntimeScheduler::startWorkLoop(jsi::Runtime& runtime) const {
break;
}
currentPriority_ = topPriorityTask->priority;
auto result = topPriorityTask->execute(runtime, didUserCallbackTimeout);
if (result.isObject() && result.getObject(runtime).isFunction(runtime)) {
topPriorityTask->callback =
result.getObject(runtime).getFunction(runtime);
} else {
if (taskQueue_.top() == topPriorityTask) {
taskQueue_.pop();
}
}
executeTask(runtime, topPriorityTask, didUserCallbackTimeout);
}
} catch (jsi::JSError& error) {
handleFatalError(runtime, error);
@@ -171,4 +151,20 @@ void RuntimeScheduler::startWorkLoop(jsi::Runtime& runtime) const {
isPerformingWork_ = false;
}
void RuntimeScheduler::executeTask(
jsi::Runtime& runtime,
std::shared_ptr<Task> task,
bool didUserCallbackTimeout) const {
currentPriority_ = task->priority;
auto result = task->execute(runtime, didUserCallbackTimeout);
if (result.isObject() && result.getObject(runtime).isFunction(runtime)) {
task->callback = result.getObject(runtime).getFunction(runtime);
} else {
if (taskQueue_.top() == task) {
taskQueue_.pop();
}
}
}
} // namespace facebook::react
@@ -133,6 +133,11 @@ class RuntimeScheduler final {
*/
void scheduleWorkLoopIfNecessary() const;
void executeTask(
jsi::Runtime& runtime,
std::shared_ptr<Task> task,
bool didUserCallbackTimeout) const;
/*
* Returns a time point representing the current point in time. May be called
* from multiple threads.