Skip to content

Commit b47c7e5

Browse files
committed
Add P3352R3 sender compatibility section to corosio paper
1 parent e4c9a94 commit b47c7e5

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

doc/research/corosio.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,36 @@ coro dispatch(coro h) const
203203
204204
If the executor must post rather than dispatch (cross-thread), it returns `std::noop_coroutine()`.
205205
206-
### 5.2 The Task Type
206+
### 5.2 Sender/Receiver Compatibility
207+
208+
The design is compatible with P3352R3 and `std::execution`. The `dispatch()` method returns a `std::coroutine_handle<>` that can be used in two ways:
209+
210+
- **Symmetric transfer** (coroutine context): Return the handle from `await_suspend`
211+
- **Explicit resume** (sender context): Call `handle.resume()` directly
212+
213+
```cpp
214+
// In a sender's completion:
215+
ex.dispatch(continuation).resume();
216+
```
217+
218+
If `dispatch()` posts work rather than dispatching inline, it returns `std::noop_coroutine()`. Calling `.resume()` on this is defined as a no-op, making the API safe in all contexts:
219+
220+
```cpp
221+
coro dispatch(coro h) const
222+
{
223+
return h; // Return for symmetric transfer OR explicit resume
224+
}
225+
226+
// Coroutine caller:
227+
return ex.dispatch(h); // Symmetric transfer
228+
229+
// Sender/callback caller:
230+
ex.dispatch(h).resume(); // Explicit resume, noop if posted
231+
```
232+
233+
This means one executor interface serves both coroutines and senders with no conditional code paths.
234+
235+
### 5.3 The Task Type
207236
208237
The `task` type represents a lazy, composable coroutine:
209238
@@ -386,6 +415,7 @@ HALO (Heap Allocation eLision Optimization) can sometimes inline coroutine frame
386415
| Runtime (deep) | Degrades with type erasure | Stable, scales well |
387416
| Allocations | 0 (native) to many (erased) | Predictable (1 per coroutine) |
388417
| Handle overhead | N/A | Zero (`handle<void>` = `handle<T>`) |
418+
| Sender compatibility | N/A | Native (`dispatch().resume()` pattern) |
389419
| Code Readability | Callback chains | Linear `co_await` sequences |
390420
| Debugging | Stack traces fragmented | Stack traces fragmented |
391421
| Encapsulation | Poor (leaky templates) | Excellent (hidden state) |
@@ -416,5 +446,6 @@ The future of asynchronous C++ is not callbacks with ever-more-elaborate templat
416446
1. N4680 - C++ Extensions for Coroutines
417447
2. P0443R14 - A Unified Executors Proposal for C++
418448
3. P2300R7 - std::execution
419-
4. Boost.Asio documentation on composed operations
420-
5. Lewis Baker, "Asymmetric Transfer" blog series
449+
4. P3352R3 - std::execution integration with coroutines
450+
5. Boost.Asio documentation on composed operations
451+
6. Lewis Baker, "Asymmetric Transfer" blog series

0 commit comments

Comments
 (0)