Skip to content

Commit

Permalink
Remove eager task types task<T> and shared_task<T>.
Browse files Browse the repository at this point in the history
These types make it difficult to write exception-safe code
when compared with their lazy-task counterparts.
  • Loading branch information
lewissbaker committed Aug 16, 2017
1 parent cf997e9 commit 64b0a04
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 2,402 deletions.
354 changes: 127 additions & 227 deletions README.md

Large diffs are not rendered by default.

521 changes: 0 additions & 521 deletions include/cppcoro/shared_task.hpp

This file was deleted.

497 changes: 0 additions & 497 deletions include/cppcoro/task.hpp

This file was deleted.

124 changes: 0 additions & 124 deletions include/cppcoro/when_all.hpp
Expand Up @@ -7,8 +7,6 @@

#include <cppcoro/lazy_task.hpp>
#include <cppcoro/shared_lazy_task.hpp>
#include <cppcoro/shared_task.hpp>
#include <cppcoro/task.hpp>
#include <cppcoro/when_all_ready.hpp>

#include <cppcoro/detail/unwrap_reference.hpp>
Expand Down Expand Up @@ -118,68 +116,6 @@ namespace cppcoro
co_return std::move(results);
}

//////////
// when_all() with vector of task

[[nodiscard]]
inline lazy_task<> when_all(std::vector<task<>> tasks)
{
// First wait until all tasks are ready using non-throwing when_ready().
for (auto& t : tasks)
{
co_await t.when_ready();
}

// Then await the value of the task so that any exceptions
// can be rethrown.
for (auto& t : tasks)
{
co_await std::move(t);
}
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<T>> when_all(std::vector<task<T>> tasks)
{
// First wait until all tasks are ready using non-throwing when_ready().
for (auto& t : tasks)
{
co_await t.when_ready();
}

std::vector<T> results;
results.reserve(tasks.size());

for (auto& t : tasks)
{
results.emplace_back(co_await std::move(t));
}

co_return std::move(results);
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<std::reference_wrapper<T>>> when_all(std::vector<task<T&>> tasks)
{
// First wait until all tasks are ready using non-throwing when_ready().
for (auto& t : tasks)
{
co_await t.when_ready();
}

std::vector<std::reference_wrapper<T>> results;
results.reserve(tasks.size());

for (auto& t : tasks)
{
results.emplace_back(co_await std::move(t));
}

co_return std::move(results);
}

//////////
// when_all() with vector of shared_lazy_task

Expand Down Expand Up @@ -228,66 +164,6 @@ namespace cppcoro

co_return std::move(results);
}

//////////
// when_all() with vector of shared_task

[[nodiscard]]
inline lazy_task<> when_all(std::vector<shared_task<>> tasks)
{
// First wait until all tasks are ready.
for (auto& t : tasks)
{
co_await t.when_ready();
}

// Then await the value of the task so that any exceptions
// can be rethrown.
for (auto& t : tasks)
{
co_await std::move(t);
}
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<T>> when_all(std::vector<shared_task<T>> tasks)
{
for (auto& t : tasks)
{
co_await t.when_ready();
}

std::vector<T> results;
results.reserve(tasks.size());

for (auto& t : tasks)
{
results.emplace_back(co_await std::move(t));
}

co_return std::move(results);
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<std::reference_wrapper<T>>> when_all(std::vector<shared_task<T&>> tasks)
{
for (auto& t : tasks)
{
co_await t.when_ready();
}

std::vector<std::reference_wrapper<T>> results;
results.reserve(tasks.size());

for (auto& t : tasks)
{
results.emplace_back(co_await std::move(t));
}

co_return std::move(results);
}
}

#endif
28 changes: 0 additions & 28 deletions include/cppcoro/when_all_ready.hpp
Expand Up @@ -7,8 +7,6 @@

#include <cppcoro/lazy_task.hpp>
#include <cppcoro/shared_lazy_task.hpp>
#include <cppcoro/shared_task.hpp>
#include <cppcoro/task.hpp>

#include <cppcoro/detail/when_all_awaitable.hpp>

Expand Down Expand Up @@ -76,19 +74,6 @@ namespace cppcoro
co_return std::move(tasks);
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<task<T>>> when_all_ready(std::vector<task<T>> tasks)
{
// All tasks already started, so just wait until they're all done.
for (auto& t : tasks)
{
co_await t.when_ready();
}

co_return std::move(tasks);
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<shared_lazy_task<T>>> when_all_ready(std::vector<shared_lazy_task<T>> tasks)
Expand Down Expand Up @@ -116,19 +101,6 @@ namespace cppcoro

co_return std::move(tasks);
}

template<typename T>
[[nodiscard]]
lazy_task<std::vector<shared_task<T>>> when_all_ready(std::vector<shared_task<T>> tasks)
{
// All tasks already started, so just wait until each one of them is done.
for (auto& t : tasks)
{
co_await t.when_ready();
}

co_return std::move(tasks);
}
}

#endif
2 changes: 0 additions & 2 deletions test/build.cake
Expand Up @@ -28,9 +28,7 @@ sources = script.cwd([
'cancellation_token_tests.cpp',
'lazy_task_tests.cpp',
'shared_lazy_task_tests.cpp',
'shared_task_tests.cpp',
'sync_wait_tests.cpp',
'task_tests.cpp',
'when_all_tests.cpp',
'when_all_ready_tests.cpp',
])
Expand Down

0 comments on commit 64b0a04

Please sign in to comment.