Commit e0519f0
committed
add support async fn in Server traits
With this commit changes how we generate the `Server` traits for
interfaces. We now generate `async fn` compatible traits instead
of methods returning `Promise`.
The methods now receive `&self` instead of `&mut self`, which
causes server implementations to need `RefCell`/`Cell` for mutable
state, similar to what we have for `Send` servers in other RPC systems.
This is slightly different from what was discussed in #577, because
we don't actually have a `Rc<impl Server>` inside `Client`, but instead
`Rc<ServerDispatch>`, making the receiver a `Rc<Self>` (which would
allow easier background processing spawning) would require an extra
allocation, pointer chasing, and ref-counting operations.
From the changes in the examples, we can see that the code is
significantly easier to understand, and `pry!` is almost never
needed. The only case I truly needed to use it was when the code
needed to manually create `Promise` due to a `RefMut` preventing
use to use `async fn` (which could cause double borrows).
In matters of breaking changes, this of course breaks every pre-existing
implementation, but it should be an easy migration. In the crates
themselves, `capnp::capability::Server` needed to be changed to receive
`Rc<Self>` instead of `&mut self`, not only the `&mut` isn't necessary
anymore but also receiving a `Rc<Self>` (which we already have where it
is called) also allow us to make the generated methods for `Server` traits
non-'static, which makes the `async fn` syntax significantly more
useful. Also, some methods in `CapabilityServerSet` which exposed the
internal `Rc<RefCell<Dispatcher>>` from `Client` needed to be changed
to return just `Rc<Dispatcher>`.
Also, given that we're using `async/await` in the generated code, they
can't be compiled in editions 2015/2018 anymore. It may be possible to
support them with some added complexity in the generated code, but I
don't think it is worth it.
Closes: #5771 parent 88900c2 commit e0519f0
File tree
21 files changed
+505
-566
lines changed- capnp-rpc
- examples
- calculator
- hello-world
- pubsub
- reconnect
- streaming
- src
- test
- capnpc
- src
- test-edition-2015
- test-edition-2018
- capnp/src
21 files changed
+505
-566
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | | - | |
33 | | - | |
| 31 | + | |
| 32 | + | |
34 | 33 | | |
35 | 34 | | |
36 | | - | |
37 | | - | |
| 35 | + | |
| 36 | + | |
38 | 37 | | |
39 | | - | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
44 | | - | |
| 43 | + | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | | - | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | | - | |
45 | | - | |
| 49 | + | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | | - | |
| 53 | + | |
49 | 54 | | |
50 | | - | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
55 | | - | |
56 | | - | |
| 60 | + | |
| 61 | + | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| |||
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
95 | | - | |
| 100 | + | |
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
100 | | - | |
| 105 | + | |
101 | 106 | | |
102 | | - | |
| 107 | + | |
103 | 108 | | |
104 | | - | |
| 109 | + | |
105 | 110 | | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
110 | | - | |
111 | | - | |
| 115 | + | |
| 116 | + | |
112 | 117 | | |
113 | 118 | | |
114 | | - | |
115 | | - | |
| 119 | + | |
| 120 | + | |
116 | 121 | | |
117 | | - | |
| 122 | + | |
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
125 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
126 | 134 | | |
127 | 135 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
132 | 139 | | |
133 | 140 | | |
134 | 141 | | |
| |||
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
141 | | - | |
142 | | - | |
| 148 | + | |
| 149 | + | |
143 | 150 | | |
144 | 151 | | |
145 | | - | |
146 | | - | |
| 152 | + | |
| 153 | + | |
147 | 154 | | |
148 | | - | |
| 155 | + | |
149 | 156 | | |
150 | 157 | | |
151 | 158 | | |
| |||
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
157 | | - | |
| 164 | + | |
158 | 165 | | |
159 | 166 | | |
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
163 | 170 | | |
164 | 171 | | |
165 | | - | |
166 | | - | |
| 172 | + | |
| 173 | + | |
167 | 174 | | |
168 | 175 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
177 | 182 | | |
178 | | - | |
179 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
180 | 186 | | |
181 | 187 | | |
182 | | - | |
| 188 | + | |
183 | 189 | | |
184 | 190 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
190 | 196 | | |
191 | | - | |
192 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
193 | 200 | | |
194 | 201 | | |
195 | | - | |
196 | | - | |
| 202 | + | |
| 203 | + | |
197 | 204 | | |
198 | 205 | | |
199 | 206 | | |
200 | | - | |
| 207 | + | |
201 | 208 | | |
202 | 209 | | |
203 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
| 22 | + | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
34 | | - | |
| 32 | + | |
| 33 | + | |
35 | 34 | | |
36 | 35 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | | - | |
32 | | - | |
| 30 | + | |
| 31 | + | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
| 37 | + | |
39 | 38 | | |
40 | | - | |
| 39 | + | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 27 | + | |
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
| |||
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
71 | | - | |
| 69 | + | |
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
| |||
77 | 75 | | |
78 | 76 | | |
79 | 77 | | |
80 | | - | |
| 78 | + | |
81 | 79 | | |
82 | 80 | | |
83 | 81 | | |
| |||
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
89 | | - | |
90 | | - | |
| 87 | + | |
| 88 | + | |
91 | 89 | | |
92 | 90 | | |
93 | | - | |
| 91 | + | |
94 | 92 | | |
95 | 93 | | |
96 | | - | |
| 94 | + | |
97 | 95 | | |
98 | | - | |
| 96 | + | |
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
106 | | - | |
| 104 | + | |
107 | 105 | | |
108 | 106 | | |
109 | 107 | | |
110 | | - | |
111 | | - | |
| 108 | + | |
| 109 | + | |
112 | 110 | | |
113 | 111 | | |
114 | 112 | | |
| |||
0 commit comments