when_all can accept non-tasks

This commit is contained in:
Martin Chang 2024-02-03 15:19:28 +08:00
parent 98608aae9b
commit df9f28a1a1
2 changed files with 9 additions and 2 deletions

View File

@ -928,7 +928,6 @@ inline Task<> when_all(std::vector<Awaiter> tasks,
trantor::EventLoop *loop = nullptr)
{
static_assert(is_awaitable_v<Awaiter>);
static_assert(std::is_same_v<await_result_t<Awaiter>, void>);
std::exception_ptr eptr;
std::atomic_size_t counter = tasks.size();
internal::WaitForNotify waiter;
@ -937,7 +936,7 @@ inline Task<> when_all(std::vector<Awaiter> tasks,
[](std::exception_ptr &eptr,
std::atomic_size_t &counter,
internal::WaitForNotify &waiter,
Task<> task) -> AsyncTask {
Awaiter task) -> AsyncTask {
try
{
co_await task;

View File

@ -281,4 +281,12 @@ DROGON_TEST(WhenAll)
CHECK(results.size() == 2);
CHECK(results[0] == 42);
CHECK(results[1] == 42);
// Check waiting on non-task works
auto sleep = sleepCoro(drogon::app().getLoop(), 0.001);
auto sleep2 = sleepCoro(drogon::app().getLoop(), 0.001);
std::vector<decltype(sleep)> tasks5;
tasks5.emplace_back(std::move(sleep));
tasks5.emplace_back(std::move(sleep2));
sync_wait(when_all(std::move(tasks5)));
}