Skip to content

to_async

faststream.utils.functions.to_async #

to_async(func)

Converts a synchronous function to an asynchronous 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."""

    @wraps(func)
    async def to_async_wrapper(*args: F_Spec.args, **kwargs: F_Spec.kwargs) -> F_Return:
        """Wraps a function to make it asynchronous."""
        return await call_or_await(func, *args, **kwargs)

    return to_async_wrapper