Converts a synchronous function to an asynchronous function.
RETURNS | DESCRIPTION |
Callable[F_Spec, Awaitable[F_Return]] | The asynchronous version of the input function. |
Source code in faststream/utils/functions.py
| def to_async(
func: Union[
Callable[F_Spec, F_Return],
Callable[F_Spec, Awaitable[F_Return]],
],
) -> Callable[F_Spec, Awaitable[F_Return]]:
"""Converts a synchronous function to an asynchronous function.
Args:
func: The synchronous function to be converted.
Returns:
The asynchronous version of the input function.
"""
@wraps(func)
async def to_async_wrapper(*args: F_Spec.args, **kwargs: F_Spec.kwargs) -> F_Return:
"""Wraps a function to make it asynchronous.
Args:
func: The function to be wrapped
args: Positional arguments to be passed to the function
kwargs: Keyword arguments to be passed to the function
Returns:
The result of the wrapped function
Raises:
Any exceptions raised by the wrapped function
"""
return await call_or_await(func, *args, **kwargs)
return to_async_wrapper
|