From 47bbf61bff38b9cc3fc1e4305f1e00c34147f34b Mon Sep 17 00:00:00 2001 From: Martin Chang Date: Fri, 2 Feb 2024 22:43:07 +0800 Subject: [PATCH] add option to when_all to switch thread --- lib/inc/drogon/utils/coroutine.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/inc/drogon/utils/coroutine.h b/lib/inc/drogon/utils/coroutine.h index 04fe71b3..272c45e5 100644 --- a/lib/inc/drogon/utils/coroutine.h +++ b/lib/inc/drogon/utils/coroutine.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -850,7 +849,7 @@ inline internal::EventLoopAwaiter queueInLoopCoro(trantor::EventLoop *loop, * @brief Waits for all tasks to complete. Throws exception if any of the tasks * throws. In such cases, all tasks are still waited for completion. */ -inline Task<> when_all(std::vector> tasks) +inline Task<> when_all(std::vector> tasks, trantor::EventLoop* loop = nullptr) { std::exception_ptr eptr; std::atomic_size_t counter = tasks.size(); @@ -878,11 +877,11 @@ inline Task<> when_all(std::vector> tasks) }(eptr, counter, waiter, std::move(task)); } co_await waiter; + if(loop) + co_await switchThreadCoro(loop); if (eptr) - { std::rethrow_exception(eptr); - } } } // namespace drogon