Files
nitro/packages/react-native-nitro-modules/cpp/threading/CallInvokerDispatcher.hpp
T
Marc RousavyandGitHub 57e7f26e61 fix: Make Nitro core compile on non-react-native environments (#195)
* fix: Make Nitro core compile on non-react-native environments

Guards `CallInvokerDispatcher` only if CallInvoker is available

* docs: Remove "Markdown page example" lol
2024-10-08 11:28:23 +02:00

39 lines
853 B
C++

//
// Created by Marc Rousavy on 27.03.24.
//
#pragma once
#include "Dispatcher.hpp"
// This is react-native specific
#if __has_include(<ReactCommon/CallInvoker.h>)
#include <ReactCommon/CallInvoker.h>
namespace margelo::nitro {
using namespace facebook;
/**
* A Dispatcher that uses react::CallInvoker for it's implementation
*/
class CallInvokerDispatcher final : public Dispatcher {
public:
explicit CallInvokerDispatcher(std::shared_ptr<react::CallInvoker> callInvoker) : _callInvoker(callInvoker) {}
void runAsync(std::function<void()>&& function) override {
_callInvoker->invokeAsync(std::move(function));
}
void runSync(std::function<void()>&& function) override {
_callInvoker->invokeSync(std::move(function));
}
private:
std::shared_ptr<react::CallInvoker> _callInvoker;
};
} // namespace margelo::nitro
#endif