Open SillyFreak opened 5 years ago
Nest function call by trio_asyncio.aio_as_trio
, instead of using decorator, and it worked.
async def test():
async with trio_asyncio.open_loop():
async def func():
await asyncio.sleep(0.1)
return 1
assert await trio_asyncio.aio_as_trio(func()) == 1
async def gen():
yield 1
await asyncio.sleep(0.1)
yield 2
assert [item async for item in trio_asyncio.aio_as_trio(gen())] == [1, 2]
@asynccontextmanager
async def ctx():
await asyncio.sleep(0.1)
yield 1
async with trio_asyncio.aio_as_trio(ctx()) as value:
assert value == 1
This behavior is described here:
Yes, but decorator would be nicer to write, because it's at the declaration site instead of at every call site. At least having the option would be good.
I was a little surprised that, when using
aio_as_trio
as a decorator, it only works on regular coroutine functions. For the followig test, only the non-commented parts work:I found that the (maybe naive?) fix was not too hard; the following works as a replacement and makes the test above work:
If there is nothing I'm missing in this adaptation, I think this would make cross calling a lot cleaner.