
The use case for your send() function is unclear to me. Why not using send() directly? inspect.getgeneratorstate(generator) == 'GEN_CREATED' test looks weird (why do you need it?). You should already know if the generator started or not. Victor 2015-02-23 12:23 GMT+01:00 Luciano Ramalho <luciano@ramalho.org>:
On Mon, Feb 23, 2015 at 7:49 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
2015-02-16 13:53 GMT+01:00 Luciano Ramalho <luciano@ramalho.org>:
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)
It's strange to have to sometimes run one iterations of the generator, sometimes two iterations.
The idea is to handle generators that may or may not be primed. I updated that snippet, it now reads like this:
https://gist.github.com/ramalho/c1f7df10308a4bd67198#file-send_builtin-py-L4...
asyncio.Task is a nice wrapper on top of coroutines, you never use coro.send() explicitly. It makes coroutines easier to use.
Yes it is, thanks! My intent was to build something that was not tied to the asyncio event loop, to make coroutines in general easier to use.
Thanks for your response, Victor.
Best,
Luciano
-- Luciano Ramalho Twitter: @ramalhoorg
Professor em: http://python.pro.br Twitter: @pythonprobr