File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,11 +91,25 @@ def _allow_asyncio(fn, *args):
9191async def allow_asyncio (fn , * args ):
9292 """
9393 This wrapper allows you to indiscrimnately mix :mod:`trio` and
94- :mod:`asyncio` functions, generators, or iterators.
94+ :mod:`asyncio` functions, generators, or iterators::
9595
96- Unfortunately, this wrapper imposes a slight delay, and there are
97- issues with cancellation (specifically, :mod:`asyncio` function will
98- see :class:`trio.Cancelled` instead of
96+ import trio
97+ import asyncio
98+ import trio_asyncio
99+
100+ async def hello(loop):
101+ await asyncio.sleep(1, loop=loop)
102+ print("Hello")
103+ await trio.sleep(1)
104+ print("World")
105+
106+ async def main():
107+ with trio_asyncio.open_loop() as loop:
108+ await trio_asyncio.allow_asyncio(hello, loop)
109+ trio.run(main)
110+
111+ Unfortunately, there are issues with cancellation (specifically,
112+ :mod:`asyncio` function will see :class:`trio.Cancelled` instead of
99113 :class:`asyncio.CancelledError`). Thus, this mode is not the default.
100114
101115 This function must be called from :mod:`trio` context.
You can’t perform that action at this time.
0 commit comments