18 lines
456 B
Python
18 lines
456 B
Python
import asyncio
|
|
import functools
|
|
|
|
from typing import Awaitable, Callable, ParamSpec, TypeVar
|
|
|
|
|
|
TA = ParamSpec("TA")
|
|
T = TypeVar("T")
|
|
|
|
|
|
def make_async(func: Callable[TA, T]) -> Callable[TA, Awaitable[T]]:
|
|
@functools.wraps(func, assigned=("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"))
|
|
async def wrapper(*args: TA.args, **kwargs: TA.kwargs):
|
|
return await asyncio.to_thread(func, *args, **kwargs)
|
|
|
|
return wrapper
|
|
|