Skip to content

Commit dadd231

Browse files
committed
Add a new Selector class
This new class acts as an async context manager and an async iterator, and makes sure no dangling tasks are left behind after a select loop is done. This class (as the failed `select()` function) is also designed to replace the current `Select` implementation with the following improvements: * Proper type hinting by using the new helper type guard `selected_from()`. * Fixes potential starvation issues. * Simplifies the interface by providing values one-by-one. * Guarantees there are no dangling tasks left behind when used as an async context manager. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 9015e7d commit dadd231

File tree

2 files changed

+605
-3
lines changed

2 files changed

+605
-3
lines changed

src/frequenz/channels/util/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,24 @@
2626
* [Select][frequenz.channels.util.Select]: A helper to select the next
2727
available message for each [receiver][frequenz.channels.Receiver] in a group
2828
of receivers.
29+
30+
* [Selector][frequenz.channels.util.Selector]: A tool to iterate over the values of all
31+
[receivers][frequenz.channels.Receiver] as new values become available.
2932
"""
3033

3134
from ._event import Event
3235
from ._file_watcher import FileWatcher
3336
from ._merge import Merge
3437
from ._merge_named import MergeNamed
35-
from ._select import Select
38+
from ._select import (
39+
Select,
40+
Selected,
41+
SelectError,
42+
SelectErrorGroup,
43+
Selector,
44+
UnhandledSelectedError,
45+
selected_from,
46+
)
3647
from ._timer import (
3748
MissedTickPolicy,
3849
SkipMissedAndDrift,
@@ -49,7 +60,13 @@
4960
"MissedTickPolicy",
5061
"Timer",
5162
"Select",
63+
"SelectError",
64+
"SelectErrorGroup",
65+
"Selected",
66+
"Selector",
5267
"SkipMissedAndDrift",
5368
"SkipMissedAndResync",
5469
"TriggerAllMissed",
70+
"UnhandledSelectedError",
71+
"selected_from",
5572
]

0 commit comments

Comments
 (0)