Skip to content
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

Generalise coroutine task<T> type to support passing through receiver context queries to parent receiver/coroutine #91

Open
lewissbaker opened this issue Mar 13, 2020 · 1 comment
Assignees

Comments

@lewissbaker
Copy link
Contributor

We would ideally like to be able to define coroutine tasks that can pass through context from the caller to child coroutines to allow passing things like stop_token, current scheduler, allocator transparently through algorithms implemented as coroutines in the same way that we do for most senders.

Since coroutines are inherently type-erased, this will mean that we need to add the ability to parameterise the task type on the set of query CPOs that should be passed through from the parent context.

template<typename T, typename... CPOs>
class task { ... };

template<typename T>
using cancellable_task = task<T,
  overload<inplace_stop_token(const this_&) noexcept>(get_stop_token)>>;

This will probably require hooking up the adaption of senders to the SenderAwaitable type to turn them into awaitables in the await_transform() rather than relying on operator co_await() so that we have the type-information from the promise early enough when defining the coroutine-receiver type to pass to the sender's connect() implementation.

Note that for some CPOs we may need to implement some special logic to adapt/type-erase across the boundary. eg. we might want to adapt from whatever stop-token type the caller has to the target stop-token type by attaching a stop_callback to the caller's stop-token. Some investigation will be required to determine what the appropriate strategy should be here.

@lewissbaker lewissbaker self-assigned this Mar 13, 2020
@lewissbaker
Copy link
Contributor Author

This has been partially implemented in #170 and #172, which add the ability to pass through stop-tokens and also have the co_await inject a receiver that forwards queries onto the promise.

Still needs some work to allow task<T> to be further parameterised with a list of other CPOs to forward through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant