@@ -148,11 +148,11 @@ export DISPATCH_ENDPOINT_URL="https://f441-2600-1700-2802-e01f-6861-dbc9-d551-ec
148
148
149
149
### Durable coroutines for Python
150
150
151
- Stateful functions can be turned into durable coroutines by declaring them
152
- * async* . When doing so, every await point becomes a durable step in the
153
- function execution: if the awaited operation fails, it is automatically
154
- retried and the parent function is paused until the result becomes available,
155
- or a permanent error is raised.
151
+ The ` @dispatch.function ` decorator can also be applied to Python coroutines
152
+ (a.k.a. * async* functions), in which case each await point on another
153
+ stateful function becomes a durability step in the execution: if the awaited
154
+ operation fails, it is automatically retried and the parent function is paused
155
+ until the result becomes available, or a permanent error is raised.
156
156
157
157
``` python
158
158
@dispatch.function
@@ -181,8 +181,22 @@ async def transform2(msg):
181
181
...
182
182
```
183
183
184
- Note that in order to provide durability guarantees, the awaited functions must
185
- be marked with the ` @dispatch.function ` decorator.
184
+ This model is composable and can be used to create fan-out/fan-in control flows.
185
+ ` gather ` can be used to wait on multiple concurrent calls to stateful functions,
186
+ for example:
187
+
188
+ ``` python
189
+ from dispatch import gather
190
+
191
+ @dispatch.function
192
+ async def process (msgs ):
193
+ concurrent_calls = [transform(msg) for msg in msgs]
194
+ return await gather(* concurrent_calls)
195
+
196
+ @dispatch.function
197
+ async def transform (msg ):
198
+ ...
199
+ ```
186
200
187
201
## Examples
188
202
0 commit comments