#ifndef IOCONTEXT_H #define IOCONTEXT_H #include "Singleton.h" #include #include class IoContext { public: enum class Mode { Synchronous, Asynchronous, }; friend class Amass::Singleton; std::shared_ptr ioContext() const { return m_ioContext; } template void run() { if constexpr (mode == Mode::Asynchronous) { m_thread = std::thread(&IoContext::runIoContext, this); } else { runIoContext(); } } void stop(); ~IoContext(); protected: template IoContext(Args &&... args) : m_ioContext(std::make_shared(std::forward(args)...)) {} void runIoContext(); private: std::thread m_thread; std::shared_ptr m_ioContext; }; #endif // IOCONTEXT_H