facebookexperimental / facebookexperimental/libunifex

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

Open
#91 1 comment 0 reactions 1 assignee Claimed by @lewissbaker View on GitHub
Dominant language
C++
Stars
1.7k
Forks
210
PR merge metrics
No merged PRs in 30d

Description

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.

```c++
template
class task { ... };

template
using cancellable_task = task(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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.