[Python-ideas] A send() built-in function to drive coroutines

Luciano Ramalho luciano at ramalho.org
Mon Feb 16 13:59:50 CET 2015


On Mon, Feb 16, 2015 at 10:53 AM, Luciano Ramalho <luciano at ramalho.org> wrote:
> At a high level, the behavior of send() would be like this:
>
> def send(coroutine, value):
>     if inspect.getgeneratorstate() == 'GEN_CREATED':
>         next(coroutine)
>     coroutine.send(value)

In the pseudo-code above I forgot a return statement in the last line.
It should read:

def send(coroutine, value):
    if inspect.getgeneratorstate() == 'GEN_CREATED':
        next(coroutine)
    return coroutine.send(value)

Best,

Luciano


-- 
Luciano Ramalho
Twitter: @ramalhoorg

Professor em: http://python.pro.br
Twitter: @pythonprobr


More information about the Python-ideas mailing list