diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp index 1141ba9bbc2..79ac8ef245c 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp @@ -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, + 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 diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h index a209f2f36fe..7bd1cb10318 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h @@ -133,6 +133,11 @@ class RuntimeScheduler final { */ void scheduleWorkLoopIfNecessary() const; + void executeTask( + jsi::Runtime& runtime, + std::shared_ptr task, + bool didUserCallbackTimeout) const; + /* * Returns a time point representing the current point in time. May be called * from multiple threads.