diff --git a/Chapter06/01_tasks_processor_base/tasks_processor_base.hpp b/Chapter06/01_tasks_processor_base/tasks_processor_base.hpp index e390ec19..bb02cfd1 100644 --- a/Chapter06/01_tasks_processor_base/tasks_processor_base.hpp +++ b/Chapter06/01_tasks_processor_base/tasks_processor_base.hpp @@ -50,11 +50,6 @@ task_wrapped make_task_wrapped(const T& task_unwrapped) { #if __has_include() # include -#else -# include - // io_service was deprecated and removed, use io_context - namespace boost::asio { using io_service = io_context; } -#endif namespace tp_base { @@ -84,4 +79,39 @@ class tasks_processor: private boost::noncopyable { } // namespace tp_base +#else +# include +# include +# include + +namespace tp_base { + +class tasks_processor: private boost::noncopyable { +protected: + static boost::asio::io_context& get_ios() { + static boost::asio::io_context ios; + static auto work = boost::asio::make_work_guard(ios); + + return ios; + } + +public: + template + static void push_task(const T& task_unwrapped) { + boost::asio::post(get_ios(), detail::make_task_wrapped(task_unwrapped)); + } + + static void start() { + get_ios().run(); + } + + static void stop() { + get_ios().stop(); + } +}; // tasks_processor + +} // namespace tp_base + +#endif // #if __has_include() + #endif // BOOK_CHAPTER6_TASK_PROCESSOR_BASE_HPP