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/50702 Changelog: [Internal] Reviewed By: rshest Differential Revision: D72865847 fbshipit-source-id: 0477670ca1f99089aece9b21feb2482b56f43936
39 lines
947 B
C++
39 lines
947 B
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 "MessageQueueThreadImpl.h"
|
|
|
|
#include <functional>
|
|
|
|
namespace facebook::react {
|
|
|
|
void MessageQueueThreadImpl::runOnQueue(std::function<void()>&& runnable) {
|
|
if (!taskDispatchThread_.isRunning()) {
|
|
return;
|
|
}
|
|
taskDispatchThread_.runAsync(
|
|
[runnable = std::move(runnable)]() noexcept { runnable(); });
|
|
}
|
|
|
|
void MessageQueueThreadImpl::runOnQueueSync(std::function<void()>&& runnable) {
|
|
if (!taskDispatchThread_.isRunning()) {
|
|
return;
|
|
}
|
|
if (taskDispatchThread_.isOnThread()) {
|
|
runnable();
|
|
} else {
|
|
taskDispatchThread_.runSync(
|
|
[runnable = std::move(runnable)]() noexcept { runnable(); });
|
|
}
|
|
}
|
|
|
|
void MessageQueueThreadImpl::quitSynchronous() {
|
|
taskDispatchThread_.quit();
|
|
}
|
|
|
|
} // namespace facebook::react
|