From Jason Turner

[exec.with.awaitable.senders]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmhpyf0jk/{from.md → to.md} +73 -0
tmp/tmpmhpyf0jk/{from.md → to.md} RENAMED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### `execution::with_awaitable_senders` <a id="exec.with.awaitable.senders">[[exec.with.awaitable.senders]]</a>
2
+
3
+ `with_awaitable_senders`, when used as the base class of a coroutine
4
+ promise type, makes senders awaitable in that coroutine type.
5
+
6
+ In addition, it provides a default implementation of `unhandled_stopped`
7
+ such that if a sender completes by calling `set_stopped`, it is treated
8
+ as if an uncatchable "stopped" exception were thrown from the
9
+ *await-expression*.
10
+
11
+ [*Note 1*: The coroutine is never resumed, and the `unhandled_stopped`
12
+ of the coroutine caller’s promise type is called. — *end note*]
13
+
14
+ ``` cpp
15
+ namespace std::execution {
16
+ template<class-type Promise>
17
+ struct with_awaitable_senders {
18
+ template<class OtherPromise>
19
+ requires (!same_as<OtherPromise, void>)
20
+ void set_continuation(coroutine_handle<OtherPromise> h) noexcept;
21
+
22
+ coroutine_handle<> continuation() const noexcept { return continuation; }
23
+
24
+ coroutine_handle<> unhandled_stopped() noexcept {
25
+ return stopped-handler(continuation.address());
26
+ }
27
+
28
+ template<class Value>
29
+ see below await_transform(Value&& value);
30
+
31
+ private:
32
+ [[noreturn]] static coroutine_handle<>
33
+ default-unhandled-stopped(void*) noexcept { // exposition only
34
+ terminate();
35
+ }
36
+ coroutine_handle<> continuation{}; // exposition only
37
+ coroutine_handle<> (*stopped-handler)(void*) noexcept = // exposition only
38
+ &default-unhandled-stopped;
39
+ };
40
+ }
41
+ ```
42
+
43
+ ``` cpp
44
+ template<class OtherPromise>
45
+ requires (!same_as<OtherPromise, void>)
46
+ void set_continuation(coroutine_handle<OtherPromise> h) noexcept;
47
+ ```
48
+
49
+ *Effects:* Equivalent to:
50
+
51
+ ``` cpp
52
+ continuation = h;
53
+ if constexpr ( requires(OtherPromise& other) { other.unhandled_stopped(); } ) {
54
+ stopped-handler = [](void* p) noexcept -> coroutine_handle<> {
55
+ return coroutine_handle<OtherPromise>::from_address(p)
56
+ .promise().unhandled_stopped();
57
+ };
58
+ } else {
59
+ stopped-handler = &default-unhandled-stopped;
60
+ }
61
+ ```
62
+
63
+ ``` cpp
64
+ template<class Value>
65
+ call-result-t<as_awaitable_t, Value, Promise&> await_transform(Value&& value);
66
+ ```
67
+
68
+ *Effects:* Equivalent to:
69
+
70
+ ``` cpp
71
+ return as_awaitable(std::forward<Value>(value), static_cast<Promise&>(*this));
72
+ ```
73
+