@@ -307,12 +307,12 @@ class Timer(Receiver[timedelta]):
307307 print(f"The timer has triggered {drift=}")
308308 ```
309309
310- But you can also use a [`Selector `][frequenz.channels.util.Selector ] to combine
310+ But you can also use a [`select `][frequenz.channels.util.select ] to combine
311311 it with other receivers, and even start it (semi) manually:
312312
313313 ```python
314314 import logging
315- from frequenz.channels.util import Selector , selected_from
315+ from frequenz.channels.util import select , selected_from
316316 from frequenz.channels import Broadcast
317317
318318 timer = Timer.timeout(timedelta(seconds=1.0), auto_start=False)
@@ -322,22 +322,21 @@ class Timer(Receiver[timedelta]):
322322 timer = Timer.timeout(timedelta(seconds=1.0), auto_start=False)
323323 # Do some other initialization, the timer will start automatically if
324324 # a message is awaited (or manually via `reset()`).
325- async with Selector(battery_data, timer) as selector:
326- async for selected in selector:
327- if selected_from(selected, battery_data):
328- if selected.was_closed():
329- logging.warning("battery channel closed")
330- continue
331- battery_soc = selected.value
332- elif selected_from(selected, timer):
333- # Print some regular battery data
334- print(f"Battery is charged at {battery_soc}%")
325+ async for selected in select(battery_data, timer):
326+ if selected_from(selected, battery_data):
327+ if selected.was_closed():
328+ logging.warning("battery channel closed")
329+ continue
330+ battery_soc = selected.value
331+ elif selected_from(selected, timer):
332+ # Print some regular battery data
333+ print(f"Battery is charged at {battery_soc}%")
335334 ```
336335
337336 Example: Timeout example
338337 ```python
339338 import logging
340- from frequenz.channels.util import Selector , selected_from
339+ from frequenz.channels.util import select , selected_from
341340 from frequenz.channels import Broadcast
342341
343342 def process_data(data: int):
@@ -351,21 +350,20 @@ def do_heavy_processing(data: int):
351350 chan2 = Broadcast[int]("input-chan-2")
352351 battery_data = chan1.new_receiver()
353352 heavy_process = chan2.new_receiver()
354- async with Selector(battery_data, heavy_process, timer) as selector:
355- async for selected in selector:
356- if selected_from(selected, battery_data):
357- if selected.was_closed():
358- logging.warning("battery channel closed")
359- continue
360- process_data(selected.value)
361- timer.reset()
362- elif selected_from(selected, heavy_process):
363- if selected.was_closed():
364- logging.warning("processing channel closed")
365- continue
366- do_heavy_processing(selected.value)
367- elif selected_from(selected, timer):
368- logging.warning("No data received in time")
353+ async for selected in select(battery_data, heavy_process, timer):
354+ if selected_from(selected, battery_data):
355+ if selected.was_closed():
356+ logging.warning("battery channel closed")
357+ continue
358+ process_data(selected.value)
359+ timer.reset()
360+ elif selected_from(selected, heavy_process):
361+ if selected.was_closed():
362+ logging.warning("processing channel closed")
363+ continue
364+ do_heavy_processing(selected.value)
365+ elif selected_from(selected, timer):
366+ logging.warning("No data received in time")
369367 ```
370368
371369 In this case `do_heavy_processing` might take 2 seconds, and we don't
0 commit comments