amis-rpc-design/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.cpp

43 lines
1.2 KiB
C++
Raw Normal View History

2023-10-07 19:42:30 +08:00
/*
* 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>
#include "RuntimeScheduler.h"
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