forked from goodboy/tractor
1
0
Fork 0

Allow opening a portal through an existing channel

stin_char_relay
Tyler Goodlet 2020-07-23 13:23:36 -04:00
parent 90499c19d7
commit 96cf4b6e9f
1 changed files with 14 additions and 10 deletions

View File

@ -314,7 +314,8 @@ class LocalPortal:
@asynccontextmanager
async def open_portal(
channel: Channel,
nursery: Optional[trio.Nursery] = None
nursery: Optional[trio.Nursery] = None,
start_msg_loop: bool = True,
) -> typing.AsyncGenerator[Portal, None]:
"""Open a ``Portal`` through the provided ``channel``.
@ -332,6 +333,8 @@ async def open_portal(
if channel.uid is None:
await actor._do_handshake(channel)
msg_loop_cs = None
if start_msg_loop:
msg_loop_cs: trio.CancelScope = await nursery.start(
partial(
actor._process_messages,
@ -352,6 +355,7 @@ async def open_portal(
await channel.send(None)
# cancel background msg loop task
if msg_loop_cs:
msg_loop_cs.cancel()
nursery.cancel_scope.cancel()