forked from goodboy/tractor
Await async funcs properly in `LocalPortal.run()`
parent
71b44b997e
commit
2973d7f1de
|
@ -768,7 +768,7 @@ async def wait_for_actor(
|
||||||
) -> typing.AsyncGenerator[Portal, None]:
|
) -> typing.AsyncGenerator[Portal, None]:
|
||||||
"""Wait on an actor to register with the arbiter.
|
"""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()
|
actor = current_actor()
|
||||||
async with get_arbiter(*arbiter_sockaddr or actor._arb_addr) as arb_portal:
|
async with get_arbiter(*arbiter_sockaddr or actor._arb_addr) as arb_portal:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
Portal api
|
Portal api
|
||||||
"""
|
"""
|
||||||
import importlib
|
import importlib
|
||||||
|
import inspect
|
||||||
import typing
|
import typing
|
||||||
from typing import Tuple, Any, Dict, Optional
|
from typing import Tuple, Any, Dict, Optional
|
||||||
|
|
||||||
|
@ -220,7 +221,11 @@ class LocalPortal:
|
||||||
"""Run a requested function locally and return it's result.
|
"""Run a requested function locally and return it's result.
|
||||||
"""
|
"""
|
||||||
obj = self.actor if ns == 'self' else importlib.import_module(ns)
|
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
|
@asynccontextmanager
|
||||||
|
|
Loading…
Reference in New Issue