File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -216,12 +216,17 @@ async def __aexit__(self, *args):
216
216
# Sleep while checking for premature ending. Return True on normal ending,
217
217
# False if premature.
218
218
async def sleep (self , t ):
219
- n , rem = divmod (t * 1000 , self ._granularity )
220
- for _ in range (n ):
219
+ t *= 1000 # ms
220
+ granularity = self ._granularity
221
+ if t <= granularity :
222
+ await asyncio .sleep_ms (t )
223
+ else :
224
+ n , rem = divmod (t , granularity )
225
+ for _ in range (n ):
226
+ if self ._ending :
227
+ return False
228
+ await asyncio .sleep_ms (granularity )
221
229
if self ._ending :
222
230
return False
223
- await asyncio .sleep_ms (self ._granularity )
224
- if self ._ending :
225
- return False
226
- await asyncio .sleep_ms (rem )
231
+ await asyncio .sleep_ms (rem )
227
232
return not self ._ending
You can’t perform that action at this time.
0 commit comments