Await async funcs properly in `LocalPortal.run()`
parent
71b44b997e
commit
2973d7f1de
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue