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