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
This commit is contained in:
Ramanpreet Nara
2019-09-20 10:52:56 -07:00
committed by Facebook Github Bot
parent 4c998fd05d
commit 1b91bfbf63
2 changed files with 57 additions and 0 deletions
@@ -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<MessageQueueThread> moduleMessageQueue)
: moduleMessageQueue_(moduleMessageQueue) {}
void MessageQueueThreadCallInvoker::invokeAsync(std::function<void()> &&func) {
moduleMessageQueue_->runOnQueue(std::move(func));
}
} // namespace react
} // namespace facebook
@@ -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 <functional>
#include <memory>
#include <ReactCommon/CallInvoker.h>
#include <cxxreact/MessageQueueThread.h>
namespace facebook {
namespace react {
/**
* Used to schedule async calls on the NativeModuels thread.
*/
class MessageQueueThreadCallInvoker : public CallInvoker {
public:
MessageQueueThreadCallInvoker(
std::shared_ptr<MessageQueueThread> moduleMessageQueue);
void invokeAsync(std::function<void()> &&func) override;
// TODO: add sync support
private:
std::shared_ptr<MessageQueueThread> moduleMessageQueue_;
};
} // namespace react
} // namespace facebook