forked from goodboy/tractor
1
0
Fork 0

Use mem chan in streaming tests

trio_memchans
Tyler Goodlet 2019-02-15 17:10:57 -05:00
parent 41c202db68
commit 51f082fff7
1 changed files with 6 additions and 6 deletions

View File

@ -91,25 +91,25 @@ async def aggregate(seed):
portals.append(portal)
q = trio.Queue(500)
send_chan, recv_chan = trio.open_memory_channel(500)
async def push_to_q(portal):
async def push_to_chan(portal):
async for value in await portal.run(
__name__, 'stream_data', seed=seed
):
# leverage trio's built-in backpressure
await q.put(value)
await send_chan.send(value)
await q.put(None)
await send_chan.send(None)
print(f"FINISHED ITERATING {portal.channel.uid}")
# spawn 2 trio tasks to collect streams and push to a local queue
async with trio.open_nursery() as n:
for portal in portals:
n.start_soon(push_to_q, portal)
n.start_soon(push_to_chan, portal)
unique_vals = set()
async for value in q:
async for value in recv_chan:
if value not in unique_vals:
unique_vals.add(value)
# yield upwards to the spawning parent actor