Skip to content

Commit df1c8ff

Browse files
committed
Make docs more cohesive with Timer constructors removal
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 8778f82 commit df1c8ff

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

docs/user-guide/utilities/timers.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
show_root_toc_entry: false
4545
show_source: false
4646

47-
## High-level Interface
47+
## Timer
4848

4949
::: frequenz.channels.timer.Timer
5050
options:
@@ -55,15 +55,7 @@
5555
show_root_toc_entry: false
5656
show_source: false
5757

58-
59-
## Low-level Interface
60-
61-
A [`Timer`][frequenz.channels.timer.Timer] can be created using an arbitrary missed
62-
ticks policy by calling the [low-level
63-
constructor][frequenz.channels.timer.Timer.__init__] and passing the policy via the
64-
[`missed_tick_policy`][frequenz.channels.timer.Timer.missed_tick_policy] argument.
65-
66-
### Custom Missed Tick Policies
58+
## Custom Missed Tick Policies
6759

6860
::: frequenz.channels.timer.MissedTickPolicy
6961
options:

src/frequenz/channels/timer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[drifts](#missed-ticks-and-drifting)), you can use
1010
a [`Timer`][frequenz.channels.timer.Timer] like this:
1111
12-
Example: Periodic Timer
12+
Example: Periodic Timer Example
1313
```python
1414
import asyncio
1515
from datetime import datetime, timedelta
@@ -25,11 +25,16 @@ async def main() -> None:
2525
asyncio.run(main())
2626
```
2727
28+
This timer will tick as close as every second as possible, even if the loop is busy
29+
doing something else for a good amount of time. In extreme cases, if the loop was
30+
busy for a few seconds, the timer will trigger a few times in a row to catch up, one
31+
for every missed tick.
32+
2833
If, instead, you need a timeout, for example to abort waiting for other receivers after
2934
a certain amount of time, you can use a [`Timer`][frequenz.channels.timer.Timer] like
3035
this:
3136
32-
Example: Timeout
37+
Example: Timeout Example
3338
```python
3439
import asyncio
3540
from datetime import timedelta
@@ -57,8 +62,10 @@ async def main() -> None:
5762
asyncio.run(main())
5863
```
5964
60-
This timer will *rearm* itself automatically after it was triggered, so it will trigger
61-
again after the selected interval, no matter what the current drift was.
65+
This timer will *rearm* itself automatically after it was triggered, so it will
66+
trigger again after the selected interval, no matter what the current drift was. So
67+
if the loop was busy for a few seconds, the timer will trigger immediately and then
68+
wait for another second before triggering again. The missed ticks are skipped.
6269
6370
Tip:
6471
It is extremely important to understand how timers behave when they are
@@ -486,7 +493,7 @@ def __init__( # pylint: disable=too-many-arguments
486493
) -> None:
487494
"""Create an instance.
488495
489-
See the class documentation for details.
496+
See the [class documentation][frequenz.channels.timer.Timer] for details.
490497
491498
Args:
492499
interval: The time between timer ticks. Must be at least

0 commit comments

Comments
 (0)