-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from goodboy/we_aint_got_zombie_shields
We aint got zombie shields
- Loading branch information
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import trio | ||
import tractor | ||
|
||
|
||
log = tractor.log.get_logger('multiportal') | ||
|
||
|
||
async def stream_data(seed=10): | ||
log.info("Starting stream task") | ||
|
||
for i in range(seed): | ||
yield i | ||
await trio.sleep(0) # trigger scheduler | ||
|
||
|
||
async def stream_from_portal(p, consumed): | ||
|
||
async for item in await p.run(stream_data): | ||
if item in consumed: | ||
consumed.remove(item) | ||
else: | ||
consumed.append(item) | ||
|
||
|
||
async def main(): | ||
|
||
async with tractor.open_nursery(loglevel='info') as an: | ||
|
||
p = await an.start_actor('stream_boi', enable_modules=[__name__]) | ||
|
||
consumed = [] | ||
|
||
async with trio.open_nursery() as n: | ||
for i in range(2): | ||
n.start_soon(stream_from_portal, p, consumed) | ||
|
||
# both streaming consumer tasks have completed and so we should | ||
# have nothing in our list thanks to single threadedness | ||
assert not consumed | ||
|
||
await an.cancel() | ||
|
||
|
||
if __name__ == '__main__': | ||
trio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters