summaryrefslogtreecommitdiff
path: root/kvmd/aiotools.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-06-06 04:04:13 +0300
committerDevaev Maxim <[email protected]>2019-06-06 04:04:13 +0300
commit288fb05ea544bb678115cca66c51efb4dc3d909b (patch)
tree5aecedb5fa24acabcb5f363641dc8b70e40c6283 /kvmd/aiotools.py
parent6d7996924f98bc33e6492e0fa9e36c321d8fb969 (diff)
refactoring
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r--kvmd/aiotools.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py
index b164e110..ef29a2df 100644
--- a/kvmd/aiotools.py
+++ b/kvmd/aiotools.py
@@ -37,14 +37,14 @@ _AtomicF = TypeVar("_AtomicF", bound=Callable[..., Any])
def atomic(method: _AtomicF) -> _AtomicF:
@functools.wraps(method)
- async def wrapper(*args: object, **kwargs: object) -> Any:
+ async def wrapper(*args: Any, **kwargs: Any) -> Any:
return (await asyncio.shield(method(*args, **kwargs)))
return typing.cast(_AtomicF, wrapper)
def tasked(method: Callable[..., Any]) -> Callable[..., asyncio.Task]:
@functools.wraps(method)
- async def wrapper(*args: object, **kwargs: object) -> asyncio.Task:
+ async def wrapper(*args: Any, **kwargs: Any) -> asyncio.Task:
return create_short_task(method(*args, **kwargs))
return typing.cast(Callable[..., asyncio.Task], wrapper)
@@ -64,3 +64,14 @@ async def gather_short_tasks() -> None:
for task in asyncio.Task.all_tasks()
if getattr(task, _ATTR_SHORT_TASK, False)
])
+
+
+_RetvalT = TypeVar("_RetvalT")
+
+
+async def run_async(method: Callable[..., _RetvalT], *args: Any) -> _RetvalT:
+ return (await asyncio.get_running_loop().run_in_executor(None, method, *args))
+
+
+def run_sync(coro: Coroutine[Any, Any, _RetvalT]) -> _RetvalT:
+ return asyncio.get_event_loop().run_until_complete(coro)