Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merge v1.2.1 into v1.x.x #336

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
```

* `Receiver.filter()` can now properly handle `TypeGuard`s. The resulting receiver will now have the narrowed type when a `TypeGuard` is used.

## Bug Fixes

- Fixed a memory leak in the timer.
20 changes: 13 additions & 7 deletions src/frequenz/channels/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,20 @@ async def ready(self) -> bool: # noqa: DOC502
# could be reset while we are sleeping, in which case we need to recalculate
# the time to the next tick and try again.
while time_to_next_tick > 0:
await next(
asyncio.as_completed(
[
asyncio.sleep(time_to_next_tick / 1_000_000),
self._reset_event.wait(),
]
)
_, pending = await asyncio.wait(
[
asyncio.create_task(asyncio.sleep(time_to_next_tick / 1_000_000)),
asyncio.create_task(self._reset_event.wait()),
],
return_when=asyncio.FIRST_COMPLETED,
)
for task in pending:
task.cancel()
try:
await task
except asyncio.CancelledError:
pass

self._reset_event.clear()
now = self._now()
time_to_next_tick = self._next_tick_time - now
Expand Down