python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio
Other
189 stars 38 forks source link

Support using asyncio async generators in trio. #14

Closed miracle2k closed 6 years ago

miracle2k commented 6 years ago

This is obviously not yet done, as missing the cancellation handling. Looking for some preliminary feedback.

It works for the following code:

import asyncio
import trio
import trio_asyncio

@trio_asyncio.trio2aio
async def asyncio_generator():
    yield 1
    await asyncio.sleep(1)
    yield 2

async def async_main(*args):
    async with trio_asyncio.open_loop() as loop:
        async for m in asyncio_generator():
            print(m)

trio.run(async_main)
codecov[bot] commented 6 years ago

Codecov Report

Merging #14 into master will decrease coverage by 2.45%. The diff coverage is 21.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #14      +/-   ##
==========================================
- Coverage   74.81%   72.36%   -2.46%     
==========================================
  Files          11       11              
  Lines         957      995      +38     
  Branches      122      126       +4     
==========================================
+ Hits          716      720       +4     
- Misses        200      232      +32     
- Partials       41       43       +2
Impacted Files Coverage Δ
trio_asyncio/loop.py 58.87% <20%> (-1.64%) :arrow_down:
trio_asyncio/adapter.py 68.42% <50%> (-11.58%) :arrow_down:
trio_asyncio/util.py 42.85% <7.69%> (-39.76%) :arrow_down:
trio_asyncio/base.py 85.71% <75%> (-0.16%) :arrow_down:
trio_asyncio/handles.py 81.72% <0%> (-2.16%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e1ae85d...3772c91. Read the comment docs.

smurfix commented 6 years ago

Could you please add a testcase or two?