mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
4c998fd05d
commit
1b91bfbf63
@@ -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
|
||||
Reference in New Issue
Block a user