[Python-ideas] A send() built-in function to drive coroutines (original) (raw)
Luciano Ramalho luciano at ramalho.org
Mon Feb 16 19:03:04 CET 2015
- Previous message: [Python-ideas] A send() built-in function to drive coroutines
- Next message: [Python-ideas] A send() built-in function to drive coroutines
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
My previous pseudo-code lost the result of next(coroutine) -- which may or may not be relevant.
I amended the send() code and wrote a few examples of it's use in a gist:
https://gist.github.com/ramalho/c1f7df10308a4bd67198
Now the user can decide whether or not to ignore the result of the priming next() call.
Best,
Luciano
On Mon, Feb 16, 2015 at 10:59 AM, Luciano Ramalho <luciano at ramalho.org> wrote:
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() == 'GENCREATED': 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() == 'GENCREATED': next(coroutine) return coroutine.send(value) Best, Luciano -- Luciano Ramalho Twitter: @ramalhoorg Professor em: http://python.pro.br Twitter: @pythonprobr
-- Luciano Ramalho Twitter: @ramalhoorg
Professor em: http://python.pro.br Twitter: @pythonprobr
- Previous message: [Python-ideas] A send() built-in function to drive coroutines
- Next message: [Python-ideas] A send() built-in function to drive coroutines
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]