Skip to content

Commit b2023ec

Browse files
committed
Use async_generator module for 3.5 support.
1 parent 365a69a commit b2023ec

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
packages=find_packages(),
6262
install_requires=[
6363
"trio",
64+
"async_generator >= 1.6",
6465
],
6566
# This means, just install *everything* you see under trio/, even if it
6667
# doesn't look like a source file, so long as it appears in MANIFEST.in:

trio_asyncio/adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This code implements a clone of the asyncio mainloop which hooks into
22
# Trio.
33

4-
import inspect
4+
from async_generator import isasyncgenfunction
55
import trio_asyncio
66

77
# import logging
@@ -13,7 +13,7 @@
1313

1414

1515
def trio2aio(proc):
16-
if inspect.isasyncgenfunction(proc):
16+
if isasyncgenfunction(proc):
1717
@wraps(proc)
1818
def call(*args):
1919
return trio_asyncio.wrap_generator(proc, *args)

trio_asyncio/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import trio
55
import asyncio
66
import sys
7+
from async_generator import async_generator, yield_
8+
79

810
__all__ = ['run_future']
911

@@ -49,6 +51,8 @@ def abort_cb(raise_cancel_arg):
4951

5052
STOP = object()
5153

54+
55+
@async_generator
5256
async def run_generator(loop, async_generator):
5357
task = trio.hazmat.current_task()
5458
raise_cancel = None
@@ -78,7 +82,7 @@ def abort_cb(raise_cancel_arg):
7882
item = await trio.hazmat.wait_task_rescheduled(abort_cb)
7983
if item is STOP:
8084
break
81-
yield item
85+
await yield_(item)
8286

8387
except asyncio.CancelledError as exc:
8488
if raise_cancel is not None:

0 commit comments

Comments
 (0)