aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-01-21 03:21:22 -0500
committerRapptz <[email protected]>2020-01-21 03:21:22 -0500
commit3149f151653137a0d8e51ba8034a080ceaaef9a3 (patch)
tree785ee2509c633dc0d9e1d33034908093aa045524
parentAdd discord.utils.sleep_until helper function (diff)
downloaddiscord.py-3149f151653137a0d8e51ba8034a080ceaaef9a3.tar.xz
discord.py-3149f151653137a0d8e51ba8034a080ceaaef9a3.zip
[tasks] Use new sleep_until util instead of internal function
-rw-r--r--discord/ext/tasks/__init__.py8
1 files changed, 2 insertions, 6 deletions
diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py
index e9d1e177..a59179b4 100644
--- a/discord/ext/tasks/__init__.py
+++ b/discord/ext/tasks/__init__.py
@@ -65,6 +65,7 @@ class Loop:
async def _loop(self, *args, **kwargs):
backoff = ExponentialBackoff()
await self._call_loop_function('before_loop')
+ sleep_until = discord.utils.sleep_until
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
try:
while True:
@@ -86,7 +87,7 @@ class Loop:
if self._current_loop == self.count:
break
- await self._sleep_until(self._next_iteration)
+ await sleep_until(self._next_iteration)
except asyncio.CancelledError:
self._is_being_cancelled = True
raise
@@ -330,11 +331,6 @@ class Loop:
self._after_loop = coro
return coro
- async def _sleep_until(self, dt):
- now = datetime.datetime.now(datetime.timezone.utc)
- delta = (dt - now).total_seconds()
- await asyncio.sleep(max(delta, 0))
-
def _get_next_sleep_time(self):
return self._last_iteration + datetime.timedelta(seconds=self._sleep)