Pass a `Channel` to `LocalPortal` for compat purposes

example_tests
Tyler Goodlet 2020-02-09 01:59:10 -05:00
parent 9fb05d8849
commit 30f8dd8be4
2 changed files with 5 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import typing
from typing import Tuple, Optional, Union from typing import Tuple, Optional, Union
from async_generator import asynccontextmanager from async_generator import asynccontextmanager
from ._ipc import _connect_chan from ._ipc import _connect_chan, Channel
from ._portal import ( from ._portal import (
Portal, Portal,
open_portal, open_portal,
@ -16,7 +16,8 @@ from ._state import current_actor
@asynccontextmanager @asynccontextmanager
async def get_arbiter( async def get_arbiter(
host: str, port: int host: str,
port: int,
) -> typing.AsyncGenerator[Union[Portal, LocalPortal], None]: ) -> typing.AsyncGenerator[Union[Portal, LocalPortal], None]:
"""Return a portal instance connected to a local or remote """Return a portal instance connected to a local or remote
arbiter. arbiter.
@ -28,7 +29,7 @@ async def get_arbiter(
if actor.is_arbiter: if actor.is_arbiter:
# we're already the arbiter # we're already the arbiter
# (likely a re-entrant call from the arbiter actor) # (likely a re-entrant call from the arbiter actor)
yield LocalPortal(actor) yield LocalPortal(actor, Channel((host, port)))
else: else:
async with _connect_chan(host, port) as chan: async with _connect_chan(host, port) as chan:
async with open_portal(chan) as arb_portal: async with open_portal(chan) as arb_portal:

View File

@ -298,6 +298,7 @@ class LocalPortal:
using an in process actor instance. using an in process actor instance.
""" """
actor: 'Actor' # type: ignore actor: 'Actor' # type: ignore
channel: Channel
async def run(self, ns: str, func_name: str, **kwargs) -> Any: async def run(self, ns: str, func_name: str, **kwargs) -> Any:
"""Run a requested function locally and return it's result. """Run a requested function locally and return it's result.