Await async funcs properly in `LocalPortal.run()`

self_register
Tyler Goodlet 2018-09-21 00:31:30 -04:00
parent 71b44b997e
commit 2973d7f1de
2 changed files with 7 additions and 2 deletions

View File

@ -768,7 +768,7 @@ async def wait_for_actor(
) -> typing.AsyncGenerator[Portal, None]:
"""Wait on an actor to register with the arbiter.
A portal to the first actor which registered is be returned.
A portal to the first registered actor is returned.
"""
actor = current_actor()
async with get_arbiter(*arbiter_sockaddr or actor._arb_addr) as arb_portal:

View File

@ -2,6 +2,7 @@
Portal api
"""
import importlib
import inspect
import typing
from typing import Tuple, Any, Dict, Optional
@ -220,7 +221,11 @@ class LocalPortal:
"""Run a requested function locally and return it's result.
"""
obj = self.actor if ns == 'self' else importlib.import_module(ns)
return getattr(obj, func)(**kwargs)
func = getattr(obj, func)
if inspect.iscoroutinefunction(func):
return await func(**kwargs)
else:
return func(**kwargs)
@asynccontextmanager