async def run_async(
func: Union[
Callable[P, T],
Callable[P, Awaitable[T]],
],
*args: P.args,
**kwargs: P.kwargs,
) -> T:
if is_coroutine_callable(func):
return await cast(Callable[P, Awaitable[T]], func)(*args, **kwargs)
else:
return await run_in_threadpool(cast(Callable[P, T], func), *args, **kwargs)