File tree Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Original file line number Diff line number Diff line change 22
33## Summary
44
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 66from typing import Any
77
88import markdown as md
9- from griffe import Object
10- from griffe .collections import ModulesCollection
9+ from griffe import ModulesCollection , Object
1110from markdown .extensions import toc
1211from mkdocs_macros import plugin as macros
1312from mkdocstrings_handlers .python .handler import PythonHandler
Original file line number Diff line number Diff line change 5555[`map()`][frequenz.channels.Receiver.map] returns a new full receiver, so you can
5656use it in any of the ways described above.
5757
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+
5877# Error Handling
5978
6079!!! Tip inline end
@@ -254,10 +273,11 @@ def filter(
254273 original receiver and use that instead.
255274
256275 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.
258278
259279 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 .
261281 """
262282 return _Filter (receiver = self , filter_function = filter_function )
263283
You can’t perform that action at this time.
0 commit comments