From 1b91bfbf636dcd5c5fb02f96460f5378d054b192 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 20 Sep 2019 10:48:50 -0700 Subject: [PATCH] Introduce MessageQueueThreadCallInvoker Summary: This abstraction will be used by TurboModules to schedule work on the NativeModules thread. Reviewed By: PeteTheHeat Differential Revision: D17422165 fbshipit-source-id: d5ca7837a0ecbcc2118813e1bafa6d445ba2ef3b --- .../MessageQueueThreadCallInvoker.cpp | 22 ++++++++++++ .../MessageQueueThreadCallInvoker.h | 35 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.cpp create mode 100644 ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.h diff --git a/ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.cpp b/ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.cpp new file mode 100644 index 00000000000..11aabc1368b --- /dev/null +++ b/ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.cpp @@ -0,0 +1,22 @@ +/** + * 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 "MessageQueueThreadCallInvoker.h" + +namespace facebook { +namespace react { + +MessageQueueThreadCallInvoker::MessageQueueThreadCallInvoker( + std::shared_ptr moduleMessageQueue) + : moduleMessageQueue_(moduleMessageQueue) {} + +void MessageQueueThreadCallInvoker::invokeAsync(std::function &&func) { + moduleMessageQueue_->runOnQueue(std::move(func)); +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.h b/ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.h new file mode 100644 index 00000000000..454ffdd24c8 --- /dev/null +++ b/ReactCommon/callinvoker/ReactCommon/MessageQueueThreadCallInvoker.h @@ -0,0 +1,35 @@ +/** + * 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. + */ + +#pragma once + +#include +#include + +#include +#include + +namespace facebook { +namespace react { + +/** + * Used to schedule async calls on the NativeModuels thread. + */ +class MessageQueueThreadCallInvoker : public CallInvoker { + public: + MessageQueueThreadCallInvoker( + std::shared_ptr moduleMessageQueue); + + void invokeAsync(std::function &&func) override; + // TODO: add sync support + + private: + std::shared_ptr moduleMessageQueue_; +}; + +} // namespace react +} // namespace facebook