On Tue, Nov 8, 2016 at 3:11 PM, Martin Richard <[email protected]>
wrote:

> The example I had in mind was a wrapper function creating a lock and
> returning a coroutine instance.
>

I suppose we could change the Lock class (and other classes like it --
probably many) to look up the loop lazily, when first needed (i.e. in
acquire or wait).


>
> Why not await the future instead of returning it?
>
> @asyncio.coroutine
> def gather(...):
>    # ...
>    return (yield from outer)
>

That's a clever idea. The downside (of this or of my original thought) is
that if gather() is called in a context that requires a future,
ensure_future() will wrap it in another layer of Task, and we just get an
endless layering of tasks and coroutines. I'd rather avoid that (unless
someone can show that this is an unlikely scenario when gather() is
involved).

Interestingly, the gather() implementation in curio does this the other way
around: curio.gather() is a coroutine, but its argument must be a list of
tasks, not coroutines.

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

Reply via email to