8000 Add std::ranges::view test for coro::when_all by jbaldwin · Pull Request #212 · jbaldwin/libcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add std::ranges::view test for coro::when_all #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion test/test_when_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <coro/coro.hpp>

#include <list>
#include <ranges>
#include <vector>

TEST_CASE("when_all single task with tuple container", "[when_all]")
Expand Down Expand Up @@ -137,4 +138,35 @@ TEST_CASE("when_all inside coroutine", "[when_all]")
auto result = coro::sync_wait(runner_task());

REQUIRE(result == (1 + 2 + 3));
}
}

TEST_CASE("when_all use std::ranges::view", "[when_all]")
{
coro::thread_pool tp{};

auto make_task = [&](uint64_t amount) -> coro::task<uint64_t>
{
co_await tp.schedule();
co_return amount;
};

auto make_runner_task = [&]() -> coro::task<uint64_t>
{
std::vector<coro::task<uint64_t>> tasks;
tasks.emplace_back(make_task(1));
tasks.emplace_back(make_task(2));
tasks.emplace_back(make_task(3));

auto output_tasks = co_await coro::when_all(std::ranges::views::all(tasks));

uint64_t result{0};
for (const auto& task : output_tasks)
{
result += task.return_value();
}
co_return result;
};

auto result = coro::sync_wait(make_runner_task());
REQUIRE(result == (1 + 2 + 3));
}
0