Skip to content

Commit 499060e

Browse files
committed
doc update
1 parent 295d543 commit 499060e

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

trio_asyncio/adapter.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,25 @@ def _allow_asyncio(fn, *args):
9191
async 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.

0 commit comments

Comments
 (0)