File tree 3 files changed +24
-17
lines changed
3 files changed +24
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Summary
4
4
5
- <!-- Here goes a general summary of what this release is about -->
6
-
7
- ## Upgrading
8
-
9
- <!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
10
-
11
- ## New Features
12
-
13
- <!-- Here goes the main new features and examples or instructions on how to use them -->
14
-
15
- ## Bug Fixes
16
-
17
- <!-- Here goes notable bug fixes that are worth a special mention or explanation -->
5
+ This release improves the documentation on ` Receiver.filter ` .
Original file line number Diff line number Diff line change 6
6
from typing import Any
7
7
8
8
import markdown as md
9
- from griffe import Object
10
- from griffe .collections import ModulesCollection
9
+ from griffe import ModulesCollection , Object
11
10
from markdown .extensions import toc
12
11
from mkdocs_macros import plugin as macros
13
12
from mkdocstrings_handlers .python .handler import PythonHandler
Original file line number Diff line number Diff line change 55
55
[`map()`][frequenz.channels.Receiver.map] returns a new full receiver, so you can
56
56
use it in any of the ways described above.
57
57
58
+ # Message Filtering
59
+
60
+ If you need to filter the received messages, receivers provide a
61
+ [`filter()`][frequenz.channels.Receiver.filter] method to easily do so:
62
+
63
+ ```python show_lines="6:"
64
+ from frequenz.channels import Anycast
65
+
66
+ channel = Anycast[int](name="test-channel")
67
+ receiver = channel.new_receiver()
68
+
69
+ async for message in receiver.filter(lambda x: x % 2 == 0):
70
+ print(message) # Only even numbers will be printed
71
+ ```
72
+
73
+ As with [`map()`][frequenz.channels.Receiver.map],
74
+ [`filter()`][frequenz.channels.Receiver.filter] returns a new full receiver, so you can
75
+ use it in any of the ways described above.
76
+
58
77
# Error Handling
59
78
60
79
!!! Tip inline end
@@ -254,10 +273,11 @@ def filter(
254
273
original receiver and use that instead.
255
274
256
275
Args:
257
- filter_function: The function to be applied on incoming messages.
276
+ filter_function: The function to be applied on incoming messages to
277
+ determine if they should be received.
258
278
259
279
Returns:
260
- A new receiver that applies the function on the received messages .
280
+ A new receiver that only receives messages that pass the filter .
261
281
"""
262
282
return _Filter (receiver = self , filter_function = filter_function )
263
283
You can’t perform that action at this time.
0 commit comments