|
43 | 43 | #include <ylt/util/expected.hpp> |
44 | 44 |
|
45 | 45 | #include "async_simple/Future.h" |
| 46 | +#include "async_simple/Signal.h" |
| 47 | +#include "async_simple/coro/LazyLocalBase.h" |
46 | 48 | #include "async_simple/coro/Mutex.h" |
47 | 49 | #include "coro_io.hpp" |
48 | 50 | #include "detail/client_queue.hpp" |
@@ -78,7 +80,11 @@ class client_pool : public std::enable_shared_from_this< |
78 | 80 | while (true) { |
79 | 81 | clients.reselect(); |
80 | 82 | self = nullptr; |
81 | | - co_await coro_io::sleep_for(sleep_time); |
| 83 | + auto is_canceled = co_await coro_io::sleep_for(sleep_time); |
| 84 | + if (!is_canceled) { |
| 85 | + ELOG_TRACE << "coroutine destroyed, stop collect timeout client"; |
| 86 | + break; |
| 87 | + } |
82 | 88 | if ((self = self_weak.lock()) == nullptr) { |
83 | 89 | break; |
84 | 90 | } |
@@ -336,6 +342,8 @@ class client_pool : public std::enable_shared_from_this< |
336 | 342 | this->weak_from_this(), clients, |
337 | 343 | (std::max)(collect_time, std::chrono::milliseconds{50}), |
338 | 344 | pool_config_.idle_queue_per_max_clear_count) |
| 345 | + .setLazyLocal( |
| 346 | + async_simple::coro::LazyLocalBase{._slot = signal_.get()}) |
339 | 347 | .directlyStart( |
340 | 348 | [](auto&&) { |
341 | 349 | }, |
@@ -565,6 +573,7 @@ class client_pool : public std::enable_shared_from_this< |
565 | 573 | } |
566 | 574 |
|
567 | 575 | const pool_config& get_pool_config() const noexcept { return pool_config_; } |
| 576 | + ~client_pool() { signal_->emits(async_simple::SignalType::Terminate); } |
568 | 577 |
|
569 | 578 | private: |
570 | 579 | template <typename, typename> |
@@ -623,6 +632,8 @@ class client_pool : public std::enable_shared_from_this< |
623 | 632 | std::atomic<uint64_t> timepoint_; |
624 | 633 | ylt::util::atomic_shared_ptr<std::vector<asio::ip::tcp::endpoint>> eps_; |
625 | 634 | async_simple::coro::Mutex dns_cache_update_mutex_; |
| 635 | + std::shared_ptr<async_simple::Signal> signal_ = |
| 636 | + async_simple::Signal::create(); |
626 | 637 | }; |
627 | 638 |
|
628 | 639 | template <typename client_t, |
|
0 commit comments