-
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 #246 from overclockworked64/patch-async-enter-all
Patch async enter all (addresses #242)
- Loading branch information
Showing
5 changed files
with
72 additions
and
37 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
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,37 @@ | ||
import itertools | ||
|
||
import trio | ||
import tractor | ||
from tractor import open_actor_cluster | ||
from tractor.trionics import async_enter_all | ||
|
||
from conftest import tractor_test | ||
|
||
|
||
MESSAGE = 'tractoring at full speed' | ||
|
||
|
||
@tractor.context | ||
async def worker(ctx: tractor.Context) -> None: | ||
await ctx.started() | ||
async with ctx.open_stream() as stream: | ||
async for msg in stream: | ||
# do something with msg | ||
print(msg) | ||
assert msg == MESSAGE | ||
|
||
|
||
@tractor_test | ||
async def test_streaming_to_actor_cluster() -> None: | ||
async with ( | ||
open_actor_cluster(modules=[__name__]) as portals, | ||
async_enter_all( | ||
mngrs=[p.open_context(worker) for p in portals.values()], | ||
) as contexts, | ||
async_enter_all( | ||
mngrs=[ctx[0].open_stream() for ctx in contexts], | ||
) as streams, | ||
): | ||
with trio.move_on_after(1): | ||
for stream in itertools.cycle(streams): | ||
await stream.send(MESSAGE) |
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
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
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