[Python-Dev] Using async/await in place of yield expression

Guido van Rossum guido at python.org
Mon Nov 27 17:05:07 EST 2017


On Mon, Nov 27, 2017 at 1:58 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> Guido van Rossum wrote:
>
>> The source for sleep() isn't very helpful -- e.g. @coroutine is mostly a
>> backwards compatibility thing.
>>
>
> So how are you supposed to write that *without* using @coroutine?
>

A simplified version using async def/await:

async def sleep(delay):
    f = Future()
    get_event_loop().call_later(delay, f.set_result)
    await f

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171127/d2764229/attachment.html>


More information about the Python-Dev mailing list