2017-03-17 13:55:44 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-03-17 13:55:44 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-03-17 13:55:44 +00:00
|
|
|
*/
|
|
|
|
|
2017-04-11 18:57:06 +00:00
|
|
|
#include <React/RCTLog.h>
|
2017-03-17 13:55:44 +00:00
|
|
|
#include <cxxreact/MessageQueueThread.h>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
// RCTNativeModule arranges for native methods to be invoked on a queue which
|
|
|
|
// is not the JS thread. C++ modules don't use RCTNativeModule, so this little
|
|
|
|
// adapter does the work.
|
|
|
|
|
|
|
|
class DispatchMessageQueueThread : public MessageQueueThread {
|
|
|
|
public:
|
|
|
|
DispatchMessageQueueThread(RCTModuleData *moduleData)
|
|
|
|
: moduleData_(moduleData) {}
|
|
|
|
|
|
|
|
void runOnQueue(std::function<void()>&& func) override {
|
2017-04-11 18:57:06 +00:00
|
|
|
dispatch_queue_t queue = moduleData_.methodQueue;
|
|
|
|
dispatch_block_t block = [func=std::move(func)] { func(); };
|
|
|
|
RCTAssert(block != nullptr, @"Invalid block generated in call to %@", moduleData_);
|
|
|
|
if (queue && block) {
|
|
|
|
dispatch_async(queue, block);
|
|
|
|
}
|
2017-03-17 13:55:44 +00:00
|
|
|
}
|
|
|
|
void runOnQueueSync(std::function<void()>&& func) override {
|
|
|
|
LOG(FATAL) << "Unsupported operation";
|
|
|
|
}
|
|
|
|
void quitSynchronous() override {
|
|
|
|
LOG(FATAL) << "Unsupported operation";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RCTModuleData *moduleData_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} }
|