Skip to content

Commit 8778f82

Browse files
committed
Remove Timer.periodic() and Timer.timeout() from docs
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent d17e44e commit 8778f82

File tree

4 files changed

+12
-61
lines changed

4 files changed

+12
-61
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ from frequenz.channels import (
110110
select,
111111
selected_from,
112112
)
113-
from frequenz.channels.timer import Timer
113+
from frequenz.channels.timer import SkipMissedAndDrift, Timer, TriggerAllMissed
114114

115115

116116
class Command(Enum):
@@ -135,7 +135,7 @@ async def send(
135135
) -> None:
136136
"""Send a counter value every second, until a stop command is received."""
137137
print(f"{sender}: Starting")
138-
timer = Timer.periodic(timedelta(seconds=1.0))
138+
timer = Timer(timedelta(seconds=1.0), TriggerAllMissed())
139139
counter = 0
140140
async for selected in select(timer, control_command):
141141
if selected_from(selected, timer):
@@ -163,7 +163,7 @@ async def receive(
163163
) -> None:
164164
"""Receive data from multiple channels, until no more data is received for 2 seconds."""
165165
print("receive: Starting")
166-
timer = Timer.timeout(timedelta(seconds=2.0))
166+
timer = Timer(timedelta(seconds=2.0), SkipMissedAndDrift())
167167
print(f"{timer=}")
168168
merged = merge(*receivers)
169169
async for selected in select(merged, timer, control_command):

docs/user-guide/utilities/timers.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,47 +55,6 @@
5555
show_root_toc_entry: false
5656
show_source: false
5757

58-
### Periodic Timers
59-
60-
::: frequenz.channels.timer.Timer.periodic
61-
options:
62-
inherited_members: []
63-
members: []
64-
show_bases: false
65-
show_root_heading: false
66-
show_root_toc_entry: false
67-
show_source: false
68-
show_docstring_attributes: false
69-
show_docstring_functions: false
70-
show_docstring_classes: false
71-
show_docstring_other_parameters: false
72-
show_docstring_parameters: false
73-
show_docstring_raises: false
74-
show_docstring_receives: false
75-
show_docstring_returns: false
76-
show_docstring_warns: false
77-
show_docstring_yields: false
78-
79-
### Timeouts
80-
81-
::: frequenz.channels.timer.Timer.timeout
82-
options:
83-
inherited_members: []
84-
members: []
85-
show_bases: false
86-
show_root_heading: false
87-
show_root_toc_entry: false
88-
show_source: false
89-
show_docstring_attributes: false
90-
show_docstring_functions: false
91-
show_docstring_classes: false
92-
show_docstring_other_parameters: false
93-
show_docstring_parameters: false
94-
show_docstring_raises: false
95-
show_docstring_receives: false
96-
show_docstring_returns: false
97-
show_docstring_warns: false
98-
show_docstring_yields: false
9958

10059
## Low-level Interface
10160

src/frequenz/channels/_select.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ async def select(*receivers: Receiver[Any]) -> AsyncIterator[Selected[Any]]:
400400
from typing import assert_never
401401
402402
from frequenz.channels import ReceiverStoppedError, select, selected_from
403-
from frequenz.channels.timer import Timer
403+
from frequenz.channels.timer import SkipMissedAndDrift, Timer, TriggerAllMissed
404404
405-
timer1 = Timer.periodic(datetime.timedelta(seconds=1))
406-
timer2 = Timer.timeout(datetime.timedelta(seconds=0.5))
405+
timer1 = Timer(datetime.timedelta(seconds=1), TriggerAllMissed())
406+
timer2 = Timer(datetime.timedelta(seconds=0.5), SkipMissedAndDrift())
407407
408408
async for selected in select(timer1, timer2):
409409
if selected_from(selected, timer1):

src/frequenz/channels/timer.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# Quick Start
77
88
If you need to do something as periodically as possible (avoiding
9-
[drifts](#missed-ticks-and-drifting)), you can use use
10-
a [`periodic()`][frequenz.channels.timer.Timer.periodic] timer.
9+
[drifts](#missed-ticks-and-drifting)), you can use
10+
a [`Timer`][frequenz.channels.timer.Timer] like this:
1111
1212
Example: Periodic Timer
1313
```python
@@ -18,16 +18,16 @@
1818
1919
2020
async def main() -> None:
21-
async for drift in Timer.periodic(timedelta(seconds=1.0)):
21+
async for drift in Timer(timedelta(seconds=1.0), TriggerAllMissed()):
2222
print(f"The timer has triggered at {datetime.now()} with a drift of {drift}")
2323
2424
2525
asyncio.run(main())
2626
```
2727
2828
If, instead, you need a timeout, for example to abort waiting for other receivers after
29-
a certain amount of time, you can use
30-
a [`timeout()`][frequenz.channels.timer.Timer.timeout] timer.
29+
a certain amount of time, you can use a [`Timer`][frequenz.channels.timer.Timer] like
30+
this:
3131
3232
Example: Timeout
3333
```python
@@ -42,7 +42,7 @@ async def main() -> None:
4242
channel = Anycast[int](name="data-channel")
4343
data_receiver = channel.new_receiver()
4444
45-
timer = Timer.timeout(timedelta(seconds=1.0))
45+
timer = Timer(timedelta(seconds=1.0), SkipMissedAndDrift())
4646
4747
async for selected in select(data_receiver, timer):
4848
if selected_from(selected, data_receiver):
@@ -472,14 +472,6 @@ class Timer(Receiver[timedelta]):
472472
[`missed_tick_policy`][frequenz.channels.timer.Timer.missed_tick_policy]. Missing
473473
ticks might or might not trigger a message and the drift could be accumulated or not
474474
depending on the chosen policy.
475-
476-
For the most common cases, a specialized constructor is provided:
477-
478-
* [`periodic()`][frequenz.channels.timer.Timer.periodic]:
479-
{{docstring_summary("frequenz.channels.timer.Timer.periodic")}}
480-
481-
* [`timeout()`][frequenz.channels.timer.Timer.timeout]:
482-
{{docstring_summary("frequenz.channels.timer.Timer.timeout")}}
483475
"""
484476

485477
def __init__( # pylint: disable=too-many-arguments

0 commit comments

Comments
 (0)