mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37623 Original commit changeset: 5f18cbe60e6c Original Phabricator Diff: D46078324 changelog: [internal] Resolves S344737 Reviewed By: FieryRobot Differential Revision: D46281951 fbshipit-source-id: dae1f7afe549686e3d5bbacf786c088bbfa49cca
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "RuntimeSchedulerCallInvoker.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace facebook::react {
|
|
|
|
RuntimeSchedulerCallInvoker::RuntimeSchedulerCallInvoker(
|
|
std::weak_ptr<RuntimeScheduler> runtimeScheduler)
|
|
: runtimeScheduler_(std::move(runtimeScheduler)) {}
|
|
|
|
void RuntimeSchedulerCallInvoker::invokeAsync(CallFunc &&func) {
|
|
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
|
runtimeScheduler->scheduleWork(
|
|
[func = std::move(func)](jsi::Runtime &) { func(); });
|
|
}
|
|
}
|
|
|
|
void RuntimeSchedulerCallInvoker::invokeSync(CallFunc &&func) {
|
|
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
|
runtimeScheduler->executeNowOnTheSameThread(
|
|
[func = std::move(func)](jsi::Runtime &) { func(); });
|
|
}
|
|
}
|
|
|
|
void RuntimeSchedulerCallInvoker::invokeAsync(
|
|
SchedulerPriority priority,
|
|
CallFunc &&func) {
|
|
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
|
runtimeScheduler->scheduleTask(
|
|
priority, [func = std::move(func)](jsi::Runtime &) { func(); });
|
|
}
|
|
}
|
|
|
|
} // namespace facebook::react
|