mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
asyncio: Optimize asyncio.sleep(0)
This commit is contained in:
parent
5be2dac560
commit
ade0412613
2 changed files with 28 additions and 0 deletions
|
@ -488,6 +488,10 @@ def as_completed(fs, *, loop=None, timeout=None):
|
|||
@coroutine
|
||||
def sleep(delay, result=None, *, loop=None):
|
||||
"""Coroutine that completes after a given time (in seconds)."""
|
||||
if delay == 0:
|
||||
yield
|
||||
return result
|
||||
|
||||
future = futures.Future(loop=loop)
|
||||
h = future._loop.call_later(delay,
|
||||
future._set_result_unless_cancelled, result)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue