// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #pragma once #include #include #include #include #include namespace Mso::React { struct MessageDispatchQueue : facebook::react::MessageQueueThread, std::enable_shared_from_this { MessageDispatchQueue( Mso::DispatchQueue const &dispatchQueue, Mso::Functor &&errorHandler, Mso::Promise &&whenQuit = nullptr) noexcept; ~MessageDispatchQueue() noexcept override; Mso::DispatchQueue const &DispatchQueue() const noexcept { return m_dispatchQueue; } public: // FastMessageQueueThread implementation void runOnQueue(std::function &&func) override; // runOnQueueSync and quitSynchronous are dangerous. They should only be // used for initialization and cleanup. void runOnQueueSync(std::function &&func) override; // Once quitSynchronous() returns, no further work should run on the queue. void quitSynchronous() override; private: void runSync(const Mso::VoidFunctorRef &func) noexcept; void tryFunc(const std::function &func) noexcept; private: std::atomic m_stopped; Mso::DispatchQueue m_dispatchQueue; Mso::Functor m_errorHandler; const Mso::Promise m_whenQuit; }; struct MessageDispatchQueue2 : facebook::react::MessageQueueThread, std::enable_shared_from_this { MessageDispatchQueue2( Mso::React::IDispatchQueue2 &dispatchQueue, Mso::Functor &&errorHandler, Mso::Promise &&whenQuit = nullptr) noexcept; ~MessageDispatchQueue2() noexcept override; public: // FastMessageQueueThread implementation void runOnQueue(std::function &&func) override; // runOnQueueSync and quitSynchronous are dangerous. They should only be // used for initialization and cleanup. void runOnQueueSync(std::function &&func) override; // Once quitSynchronous() returns, no further work should run on the queue. void quitSynchronous() override; private: void runSync(const Mso::VoidFunctorRef &func) noexcept; void tryFunc(const std::function &func) noexcept; private: std::atomic m_stopped; Mso::CntPtr m_dispatchQueue; Mso::Functor m_errorHandler; const Mso::Promise m_whenQuit; }; } // namespace Mso::React