File indexing completed on 2025-04-19 08:33:50
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_CONNECTION_POOL_WAIT_GROUP_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_CONNECTION_POOL_WAIT_GROUP_HPP
0010
0011 #include <boost/mysql/error_code.hpp>
0012
0013 #include <boost/asio/any_io_executor.hpp>
0014 #include <boost/asio/bind_executor.hpp>
0015 #include <boost/asio/steady_timer.hpp>
0016
0017 #include <chrono>
0018 #include <cstddef>
0019
0020 namespace boost {
0021 namespace mysql {
0022 namespace detail {
0023
0024 class wait_group
0025 {
0026 std::size_t running_tasks_{};
0027 asio::steady_timer finished_;
0028
0029 public:
0030 wait_group(asio::any_io_executor ex)
0031 : finished_(std::move(ex), (std::chrono::steady_clock::time_point::max)())
0032 {
0033 }
0034
0035 asio::any_io_executor get_executor() { return finished_.get_executor(); }
0036
0037 void on_task_start() noexcept { ++running_tasks_; }
0038
0039 void on_task_finish() noexcept
0040 {
0041 if (--running_tasks_ == 0u)
0042 finished_.cancel();
0043 }
0044
0045
0046
0047 template <class CompletionToken>
0048 void async_wait(CompletionToken&& token)
0049 {
0050 return finished_.async_wait(std::forward<CompletionToken>(token));
0051 }
0052
0053
0054
0055 template <class Op>
0056 void run_task(Op&& op)
0057 {
0058 on_task_start();
0059 std::forward<Op>(op)(asio::bind_executor(get_executor(), [this](error_code) { on_task_finish(); }));
0060 }
0061 };
0062
0063 }
0064 }
0065 }
0066
0067 #endif