#pragma once #include #include namespace utils { class MessangerService : public boost::asio::execution_context::service { public: using key_type = MessangerService; struct Context { std::vector handlers; }; MessangerService(boost::asio::execution_context& execution_context); ~MessangerService() = default; void shutdown() {} Context& create(); void destroy(Context& context); template void send(const T& event) { using HandlerType = std::function; for (const auto& context : contexts_) { for (const auto& any : context->handlers) { if (const HandlerType* handler = std::any_cast(&any)) { (*handler)(event); } } } } static boost::asio::execution_context::id id; private: std::vector> contexts_; }; } // namespace utils