You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Often it's useful to be able to co_await multiple awaitables in parallel. Note that there is a pre-existing task (#74) and even a branch (feature/composition), which got stalled due to any/|| not being possible without cancellation support in QCoro::Task<T>
QCoro2::all() / &&
QCoro2::all() takes an arbitrary number of awaitables and returns a single Task<T> that resolves when all the inner awaitables resolve. && is just a syntactic sugar.
The return type would be a tuple with results of all awaitables:
** TODO: What should really be the return type here if Ts are mixed RTasks and Tasks or other awaitables?**
Additionally, we should provide overloads for different behaviors:
// Force lazy evaluation of the entire group. If a group member is eager, it's still evaluated eagerly,// but if there are lazy taks, they do get evaluated lazilytemplate<typename ... Awaitable Ts>
autoall(Lazy, Ts... &&ts) -> QCoro::LazyTask<std::tuple<awaitable_result_t<Ts> ...>>
// Force lazy evaluation with possibility for cancellation. Requires all tasks to be RTask or LazyRTask.// Same behavior as `Lazy`, but can be cancelled at any time.
template<typename ... RTaskLike Ts>
auto all(LazyCancellable, Ts... &&ts) -> QCoro2::LazyRTask<std::tuple<awaitable_result_t<Ts> ...>>
// Force possibility for cancellation. Requires all tasks to be RTask or LazyRTask.
template<typename ... RTaskLike Ts>
auto all(Cancellable, Ts ...&&ts) -> QCoro2::RTask<std::tuple<awaitable_result_t<Ts> ...>>
operator &&:
TODO: How to treat different combinations of awaitable types?
QCoro2::any is like QCoro2::all(), except it resolves the moment any awaitable finishes, returning its result and cancelling all the other awaitables.
The signature is mostly identical to all(), except for the return type. It should accept any awaitable, but have a special casing for Task<T> where it would cancel it if it does not win the race. If the awaitable is not Task<T>, the documentation must be clear on the fact that it will be left to run to completion, but its result will be discarded.
The return type would once again be std::tuple, but it would be a std::tuple of std::optionals, indicating which awaitable was the winner:
TODO: Lazy evaluation TODO: Properly define the semantics for non-cancellable types - maybe don't allow them at all? What's the point of using any if you can't cancel the other tasks anyway...
Often it's useful to be able to
co_await
multiple awaitables in parallel. Note that there is a pre-existing task (#74) and even a branch (feature/composition
), which got stalled due toany
/||
not being possible without cancellation support inQCoro::Task<T>
QCoro2::all()
/&&
QCoro2::all()
takes an arbitrary number of awaitables and returns a singleTask<T>
that resolves when all the inner awaitables resolve.&&
is just a syntactic sugar.The return type would be a tuple with results of all awaitables:
** TODO: What should really be the return type here if
Ts
are mixedRTask
s andTask
s or other awaitables?**Additionally, we should provide overloads for different behaviors:
operator &&
:TODO: How to treat different combinations of awaitable types?
Usage:
QCoro2::any()
/||
QCoro2::any
is likeQCoro2::all()
, except it resolves the moment any awaitable finishes, returning its result and cancelling all the other awaitables.The signature is mostly identical to
all()
, except for the return type. It should accept any awaitable, but have a special casing forTask<T>
where it would cancel it if it does not win the race. If the awaitable is notTask<T>
, the documentation must be clear on the fact that it will be left to run to completion, but its result will be discarded.The return type would once again be
std::tuple
, but it would be astd::tuple
ofstd::optional
s, indicating which awaitable was the winner:TODO: Lazy evaluation
TODO: Properly define the semantics for non-cancellable types - maybe don't allow them at all? What's the point of using
any
if you can't cancel the other tasks anyway...The text was updated successfully, but these errors were encountered: