forked from goodboy/tractor
Adjust streaming ex to use memory channel
parent
78ddd33e3a
commit
fd4e126e1f
|
@ -371,16 +371,16 @@ and print the results to your screen:
|
||||||
|
|
||||||
portals.append(portal)
|
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_q(portal):
|
||||||
async for value in await portal.run(
|
async for value in await portal.run(
|
||||||
__name__, 'stream_data', seed=seed
|
__name__, 'stream_data', seed=seed
|
||||||
):
|
):
|
||||||
# leverage trio's built-in backpressure
|
# 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}")
|
print(f"FINISHED ITERATING {portal.channel.uid}")
|
||||||
|
|
||||||
# spawn 2 trio tasks to collect streams and push to a local queue
|
# spawn 2 trio tasks to collect streams and push to a local queue
|
||||||
|
@ -389,7 +389,7 @@ and print the results to your screen:
|
||||||
n.start_soon(push_to_q, portal)
|
n.start_soon(push_to_q, portal)
|
||||||
|
|
||||||
unique_vals = set()
|
unique_vals = set()
|
||||||
async for value in q:
|
async for value in recv_chan:
|
||||||
if value not in unique_vals:
|
if value not in unique_vals:
|
||||||
unique_vals.add(value)
|
unique_vals.add(value)
|
||||||
# yield upwards to the spawning parent actor
|
# yield upwards to the spawning parent actor
|
||||||
|
|
Loading…
Reference in New Issue