You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the timer generic and support periodic timers (#79)
The current timer provided is very convenient to implement timers, but
it's not very helpful to implement a peridic timer that doesn't
accumulate drift.
This PR makes the timer configurable via *missing ticks policies* and
adds 3 policies: `TriggerAllMissing`, `SkipMissingAndResync` and
`SkipMissingAndDrift`.
For convenience, 2 alternative constructors are provided for the most
common cases: `Timer.timeout()` and `Timer.periodic()`. Timeout timers
always drift and periodic timers never.
The new `Timer` also uses the `asyncio` loop monotonic clock, and
returns the `drift` (difference between when the timer should have
triggered and it actually did) instead of a `datetime` with the time of
trigger.
It is also now possible to control when this timer is started, and can
be stopped and reset/restarted at will.
Fixes#78.
Copy file name to clipboardExpand all lines: RELEASE_NOTES.md
+29-4Lines changed: 29 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,41 @@
2
2
3
3
## Summary
4
4
5
-
<!-- Here goes a general summary of what this release is about -->
5
+
This release adds support to pass `None` values via channels and revamps the `Timer` class to support custom policies for handling missed ticks and use the loop monotonic clock.
6
6
7
7
## Upgrading
8
8
9
-
<!-- Here goes notes on how to upgrade from previous versions, including if there are any depractions and what they should be replaced with -->
9
+
*`util.Timer` was replaced by a more generic implementation that allows for customizable policies to handle missed ticks.
10
+
11
+
If you were using `Timer` to implement timeouts, these two pices of code should be almost equivalent:
They are not**exactly** the same because the `triggered_datetime`in the second case will not be exactly when the timer had triggered, but that shouldn't be relevant, the important part is when your code can actually react to the timer trigger and to know how much drift there was to be able to take corrective actions.
29
+
30
+
Also the new `Timer` uses the `asyncio` loop monotonic clock and the old one used the wall clock (`datetime.now()`) to track time. This means that when using `async-solipsism` to test, the new `Timer` will always trigger immediately regarless of the state of the wall clock.
31
+
32
+
**Note:** Before replacing this code blindly inall uses of `Timer.timeout()`, please consider using the periodic timer constructor `Timer.periodic()`if you need a timer that triggers reliable on a periodic fashion, as the old `Timer` (and`Timer.timeout()`) accumulates drift, which might not be what you want.
10
33
11
34
## New Features
12
35
13
-
<!-- Here goes the main new features and examples or instructions on how to use them -->
36
+
*`util.Timer` was replaced by a more generic implementation that allows for customizable policies to handle missed ticks.
37
+
38
+
* Passing `None` values via channels is now supported.
14
39
15
40
## Bug Fixes
16
41
17
-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
42
+
*`util.Select`/`util.Merge`/`util.MergeNamed`: Cancel pending tasks in`__del__` methods only if possible (the loop isnot already closed).
0 commit comments