Skip to content

Commit 1013a72

Browse files
committed
Improve the Example section to host more than one example
Also add the expected output for the example. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0596041 commit 1013a72

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/frequenz/sdk/actor/__init__.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,22 @@ class and implement the abstract `_run()` method.
195195
any other more graceful way to stop the actor if you need to make sure it can't be
196196
interrupted at any `await` point.
197197
198-
## Example
198+
### Examples
199199
200-
Here's a simple example to demonstrate how to create two actors and connect
201-
them.
200+
Here are a few simple but complete examples to demonstrate how to create create actors
201+
and connect them using [channels][frequenz.channels].
202202
203-
Please note the annotations in the code (like {{code_annotation_marker}}), they
204-
explain step-by-step what's going on in order of execution.
203+
!!! tip
205204
206-
```python title="actors.py"
205+
The code examples are annotated with markers (like {{code_annotation_marker}}), they
206+
explain step-by-step what's going on in order of execution.
207+
208+
#### Composing actors
209+
210+
This example shows how to create two actors and connect them using
211+
[broadcast][frequenz.channels.Broadcast] channels.
212+
213+
```python title="compose.py"
207214
import asyncio
208215
209216
from frequenz.channels import Broadcast, Receiver, Sender
@@ -306,6 +313,12 @@ async def main() -> None: # (2)!
306313
11. The actors are stopped and cleaned up automatically when the `async with`
307314
block ends.
308315
316+
The expected output is:
317+
318+
```
319+
Actor2 forwarding: "Actor1 forwarding: 'Hello'"
320+
```
321+
309322
[async context manager]: https://docs.python.org/3/reference/datamodel.html#async-context-managers
310323
"""
311324

0 commit comments

Comments
 (0)