mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
ea3e244668
Summary: changelog: [internal] Reviewed By: RSNara Differential Revision: D31145372 fbshipit-source-id: b1d9473d5006d055d1116f71f65899293fb85c56
33 lines
970 B
C++
33 lines
970 B
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its 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"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
RuntimeSchedulerCallInvoker::RuntimeSchedulerCallInvoker(
|
|
std::weak_ptr<RuntimeScheduler> runtimeScheduler)
|
|
: runtimeScheduler_(runtimeScheduler) {}
|
|
|
|
void RuntimeSchedulerCallInvoker::invokeAsync(std::function<void()> &&func) {
|
|
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
|
runtimeScheduler->scheduleWork(
|
|
[func = std::move(func)](jsi::Runtime &) { func(); });
|
|
}
|
|
}
|
|
|
|
void RuntimeSchedulerCallInvoker::invokeSync(std::function<void()> &&func) {
|
|
if (auto runtimeScheduler = runtimeScheduler_.lock()) {
|
|
runtimeScheduler->executeNowOnTheSameThread(
|
|
[func = std::move(func)](jsi::Runtime &) { func(); });
|
|
}
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|