[tasks] Use new sleep_until util instead of internal function
This commit is contained in:
parent
40369a493d
commit
3149f15165
@ -65,6 +65,7 @@ class Loop:
|
|||||||
async def _loop(self, *args, **kwargs):
|
async def _loop(self, *args, **kwargs):
|
||||||
backoff = ExponentialBackoff()
|
backoff = ExponentialBackoff()
|
||||||
await self._call_loop_function('before_loop')
|
await self._call_loop_function('before_loop')
|
||||||
|
sleep_until = discord.utils.sleep_until
|
||||||
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
|
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@ -86,7 +87,7 @@ class Loop:
|
|||||||
if self._current_loop == self.count:
|
if self._current_loop == self.count:
|
||||||
break
|
break
|
||||||
|
|
||||||
await self._sleep_until(self._next_iteration)
|
await sleep_until(self._next_iteration)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
self._is_being_cancelled = True
|
self._is_being_cancelled = True
|
||||||
raise
|
raise
|
||||||
@ -330,11 +331,6 @@ class Loop:
|
|||||||
self._after_loop = coro
|
self._after_loop = coro
|
||||||
return 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):
|
def _get_next_sleep_time(self):
|
||||||
return self._last_iteration + datetime.timedelta(seconds=self._sleep)
|
return self._last_iteration + datetime.timedelta(seconds=self._sleep)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user