forked from goodboy/tractor
1
0
Fork 0

Type out the full-fledged streaming ex.

multihomed
Tyler Goodlet 2023-10-18 15:36:00 -04:00
parent 1e689ee701
commit 6b1ceee19f
1 changed files with 14 additions and 7 deletions

View File

@ -65,21 +65,28 @@ async def aggregate(seed):
print("AGGREGATOR COMPLETE!") print("AGGREGATOR COMPLETE!")
# this is the main actor and *arbiter* async def main() -> list[int]:
async def main(): '''
# a nursery which spawns "actors" This is the "root" actor's main task's entrypoint.
async with tractor.open_nursery(
arbiter_addr=('127.0.0.1', 1616) By default (and if not otherwise specified) that root process
) as nursery: also acts as a "registry actor" / "registrar" on the localhost
for the purposes of multi-actor "service discovery".
'''
# yes, a nursery which spawns `trio`-"actors" B)
nursery: tractor.ActorNursery
async with tractor.open_nursery() as nursery:
seed = int(1e3) seed = int(1e3)
pre_start = time.time() pre_start = time.time()
portal = await nursery.start_actor( portal: tractor.Portal = await nursery.start_actor(
name='aggregator', name='aggregator',
enable_modules=[__name__], enable_modules=[__name__],
) )
stream: tractor.MsgStream
async with portal.open_stream_from( async with portal.open_stream_from(
aggregate, aggregate,
seed=seed, seed=seed,