@@ -287,43 +287,61 @@ class Timer(Receiver[timedelta]):
287287 with other receivers, and even start it (semi) manually:
288288
289289 ```python
290+ import logging
291+ from frequenz.channels.util import Select
292+ from frequenz.channels import Broadcast
293+
294+ timer = Timer.timeout(timedelta(seconds=1.0), auto_start=False)
295+ chan = Broadcast[int]("input-chan")
296+ receiver1 = chan.new_receiver()
297+
290298 timer = Timer.timeout(timedelta(seconds=1.0), auto_start=False)
291299 # Do some other initialization, the timer will start automatically if
292300 # a message is awaited (or manually via `reset()`).
293301 select = Select(bat_1=receiver1, timer=timer)
294302 while await select.ready():
295303 if msg := select.bat_1:
296304 if val := msg.inner:
297- process_data( val)
305+ battery_soc = val
298306 else:
299- logging.warn ("battery channel closed")
307+ logging.warning ("battery channel closed")
300308 elif drift := select.timer:
301309 # Print some regular battery data
302- print(f"Battery is charged at {battery.soc}%")
303- if stop_logging:
304- timer.stop()
305- elif start_logging:
306- timer.reset()
310+ print(f"Battery is charged at {battery_soc}%")
307311 ```
308312
309313 Example: Timeout example
310314 ```python
315+ import logging
316+ from frequenz.channels.util import Select
317+ from frequenz.channels import Broadcast
318+
319+ def process_data(data: int):
320+ logging.info("Processing data: %d", data)
321+
322+ def do_heavy_processing(data: int):
323+ logging.info("Heavy processing data: %d", data)
324+
311325 timer = Timer.timeout(timedelta(seconds=1.0), auto_start=False)
326+ chan1 = Broadcast[int]("input-chan-1")
327+ chan2 = Broadcast[int]("input-chan-2")
328+ receiver1 = chan1.new_receiver()
329+ receiver2 = chan2.new_receiver()
312330 select = Select(bat_1=receiver1, heavy_process=receiver2, timeout=timer)
313331 while await select.ready():
314332 if msg := select.bat_1:
315333 if val := msg.inner:
316334 process_data(val)
317335 timer.reset()
318336 else:
319- logging.warn ("battery channel closed")
337+ logging.warning ("battery channel closed")
320338 if msg := select.heavy_process:
321339 if val := msg.inner:
322340 do_heavy_processing(val)
323341 else:
324- logging.warn ("processing channel closed")
342+ logging.warning ("processing channel closed")
325343 elif drift := select.timeout:
326- logging.warn ("No data received in time")
344+ logging.warning ("No data received in time")
327345 ```
328346
329347 In this case `do_heavy_processing` might take 2 seconds, and we don't
0 commit comments