falcon_auth2/utils/functions.py
def call_maybe_async(
    support_async: bool,
    function_is_async: Optional[bool],
    err_msg: str,
    function: Callable,
    *args,
    **kwargs,
) -> Tuple[Any, bool]:
    """Calls a function and waits for the result if it is async.

    Args:
        support_async (bool): Can run async cuntions.
        function_is_async (Optional[bool]): If the function is async. This function will determine
            if ``function`` is async when this parameter is ``None``.
        err_msg (str): Name of the function. Used in case of error.
        function (Callable): The function to call.
        \\*args: Positional arguments to pass to the ``function`` callable.
        \\*\\*kwargs: Keyword arguments to pass to the ``function`` callable.

    Raises:
        TypeError: if ``function`` is async and ``support_async=False``.

    Returns:
        Tuple[Any, bool]: Returns the result and whatever the function is async.
    """
    result = function(*args, **kwargs)
    if function_is_async is None:
        function_is_async = iscoroutine(result)

    if function_is_async:
        if support_async:
            # result is a coroutine here. await it
            result = await_(result)
        else:
            raise TypeError(
                f"Cannot use async {err_msg} {function} when"
                " falcon is not running in async mode (asgi)."
            )
    return result, function_is_async
Calls a function and waits for the result if it is async.

    Args:
        support_async (bool): Can run async cuntions.
        function_is_async (Optional[bool]): If the function is async. This function will determine
            if ``function`` is async when this parameter is ``None``.
        err_msg (str): Name of the function. Used in case of error.
        function (Callable): The function to call.
        \\*args: Positional arguments to pass to the ``function`` callable.
        \\*\\*kwargs: Keyword arguments to pass to the ``function`` callable.

    Raises:
        TypeError: if ``function`` is async and ``support_async=False``.

    Returns:
        Tuple[Any, bool]: Returns the result and whatever the function is async.
    
Calls a function and waits for the result if it is async.
Calls a function and waits for the result if it is async .
def call_maybe_async(
    support_async: bool,
    function_is_async: Optional[bool],
    err_msg: str,
    function: Callable,
    *args,
    **kwargs,
) -> Tuple[Any, bool]:
    result = function(*args, **kwargs)
    if function_is_async is None:
        function_is_async = iscoroutine(result)
    if function_is_async:
        if support_async:
            result = await_(result)
        else:
            raise TypeError(
                f"Cannot use async {err_msg} {function} when"
                " falcon is not running in async mode (asgi)."
            )
    return result, function_is_async
def call_maybe_async ( support_async : bool , function_is_async : Optional [ bool ] , err_msg : str , function : Callable , * args , ** kwargs , ) -> Tuple [ Any , bool ] : result = function ( * args , ** kwargs ) if function_is_async is None : function_is_async = iscoroutine ( result ) if function_is_async : if support_async : result = await_ ( result ) else : raise TypeError ( f"Cannot use async {err_msg} {function} when" " falcon is not running in async mode (asgi)." ) return result , function_is_async
Calls a function and waits for the result if it is async.
Calls a function and waits for the result if it is async .
"""Calls a function and waits for the result if it is async.

    Args:
        support_async (bool): Can run async cuntions.
        function_is_async (Optional[bool]): If the function is async. This function will determine
            if ``function`` is async when this parameter is ``None``.
        err_msg (str): Name of the function. Used in case of error.
        function (Callable): The function to call.
        \\*args: Positional arguments to pass to the ``function`` callable.
        \\*\\*kwargs: Keyword arguments to pass to the ``function`` callable.

    Raises:
        TypeError: if ``function`` is async and ``support_async=False``.

    Returns:
        Tuple[Any, bool]: Returns the result and whatever the function is async.
    """ # result is a coroutine here. await it
Returns the result and whatever the function is async.
Returns the result and whatever the function is async .
Tuple[Any, bool]
if ``function`` is async and ``support_async=False``.
if ` ` function ` ` is async and ` ` support_async = False ` ` .
TypeError
support_async
bool
Can run async cuntions.
Can run async cuntions .
function_is_async
Optional[bool]
If the function is async. This function will determine
if ``function`` is async when this parameter is ``None``.
If the function is async . This function will determine if ` ` function ` ` is async when this parameter is ` ` None ` ` .
err_msg
str
Name of the function. Used in case of error.
Name of the function . Used in case of error .
function
Callable
The function to call.
The function to call .
\\*args
Positional arguments to pass to the ``function`` callable.
Positional arguments to pass to the ` ` function ` ` callable .
\\*\\*kwargs
Keyword arguments to pass to the ``function`` callable.
Keyword arguments to pass to the ` ` function ` ` callable .