|
73 | 73 |
|
74 | 74 | When a single [receiver][frequenz.channels.Receiver] is stopped, it will be reported |
75 | 75 | via the [`Selected`][frequenz.channels.Selected] object. You can use the |
76 | | -[`was_stopped()`][frequenz.channels.Selected.was_stopped] method to check if the |
| 76 | +[`was_stopped`][frequenz.channels.Selected.was_stopped] method to check if the |
77 | 77 | selected [receiver][frequenz.channels.Receiver] was stopped: |
78 | 78 |
|
79 | 79 | ```python show_lines="8:" |
|
86 | 86 |
|
87 | 87 | async for selected in select(receiver1, receiver2): |
88 | 88 | if selected_from(selected, receiver1): |
89 | | - if selected.was_stopped(): |
| 89 | + if selected.was_stopped: |
90 | 90 | print("receiver1 was stopped") |
91 | 91 | continue |
92 | 92 | print(f"Received from receiver1, the next number is: {selected.value + 1}") |
93 | 93 | # ... |
94 | 94 | ``` |
95 | 95 |
|
96 | 96 | Tip: |
97 | | - The [`was_stopped()`][frequenz.channels.Selected.was_stopped] method is a |
| 97 | + The [`was_stopped`][frequenz.channels.Selected.was_stopped] method is a |
98 | 98 | convenience method that is equivalent to checking if the |
99 | 99 | [`exception`][frequenz.channels.Selected.exception] attribute is an instance of |
100 | 100 | [`ReceiverStoppedError`][frequenz.channels.ReceiverStoppedError]. |
@@ -228,16 +228,9 @@ def exception(self) -> Exception | None: |
228 | 228 | """ |
229 | 229 | return self._exception |
230 | 230 |
|
| 231 | + @property |
231 | 232 | def was_stopped(self) -> bool: |
232 | | - """Check if the selected receiver was stopped. |
233 | | -
|
234 | | - Check if the selected receiver raised |
235 | | - a [`ReceiverStoppedError`][frequenz.channels.ReceiverStoppedError] while |
236 | | - consuming a value. |
237 | | -
|
238 | | - Returns: |
239 | | - Whether the receiver was stopped. |
240 | | - """ |
| 233 | + """Whether the selected receiver was stopped while receiving a value.""" |
241 | 234 | return isinstance(self._exception, ReceiverStoppedError) |
242 | 235 |
|
243 | 236 | def __str__(self) -> str: |
|
0 commit comments