[Python-Dev] [Python-ideas] PEP 3156 - Asynchronous IO Support Rebooted

Guido van Rossum guido at python.org
Sat Dec 22 02:03:26 CET 2012

On Fri, Dec 21, 2012 at 2:26 PM, Jonathan Slenders <jonathan at slenders.be> wrote:
> As far as I understand, "yield from" will always work, because a Future
> object can act like an iterator, and you can delegate your own generator to
> this iterator at the place of "yield from".
> "yield" only works if the parameter behind yield is already a Future object.
> Right Guido?

Correct! Sounds like you got it now.

That's the magic of yield from..

> In case of sleep, sleep could be implemented to return a Future object.

It does; in tulip/futures.py:

def sleep(when, result=None):
    future = Future()
    future._event_loop.call_later(when, future.set_result, result)
    return future

--Guido van Rossum (python.org/~guido)

More information about the Python-Dev mailing list