Skip to content

Commit

Permalink
Fix timeout calculation in scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
kinnay committed Mar 3, 2022
1 parent cdf9449 commit d952763
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions anynet/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async def process(self):
self.event = anyio.Event()

def process_timers(self):
minimum = None
current = time.monotonic()
items = self.events.copy().items()
for handle, (deadline, repeat, function, args) in items:
Expand All @@ -34,10 +33,9 @@ def process_timers(self):
if repeat is not None:
self.events[handle] = (deadline + repeat, repeat, function, args)
self.group.start_soon(function, *args)
else:
if minimum is None or minimum > deadline - current:
minimum = deadline - current
return minimum

timeouts = [event[0] - current for event in self.events.values()]
return min(timeouts, default=None)

def schedule(self, function, delay, *args):
deadline = time.monotonic() + delay
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name = "anynet",
version = "0.0.12",
version = "0.0.13",
description = "Networking library based on anyio",
long_description = long_description,
author = "Yannik Marchand",
Expand Down

0 comments on commit d952763

Please sign in to comment.