mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
of a Future with call_soon(). Add an helper, a private method, to set the result only if the future was not cancelled.
This commit is contained in:
parent
5021cb553c
commit
a9acbe82e7
9 changed files with 31 additions and 7 deletions
|
@ -487,7 +487,8 @@ def as_completed(fs, *, loop=None, timeout=None):
|
|||
def sleep(delay, result=None, *, loop=None):
|
||||
"""Coroutine that completes after a given time (in seconds)."""
|
||||
future = futures.Future(loop=loop)
|
||||
h = future._loop.call_later(delay, future.set_result, result)
|
||||
h = future._loop.call_later(delay,
|
||||
future._set_result_unless_cancelled, result)
|
||||
try:
|
||||
return (yield from future)
|
||||
finally:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue