async def run_maybe_sync(fn: Callable[P, T | Awaitable[T]], *args: P.args, **kwargs: P.kwargs) -> T:
    """Executes a callable function and handles both synchronous and asynchronous
    results.

    This function invokes the provided callable `sync_fn` with the given
    arguments and keyword arguments. If the result of `sync_fn` is awaitable,
    it awaits the result before returning it. Otherwise, the result is returned
    directly.

    Args:
        fn: The callable to be executed. It can produce either a
            synchronous or asynchronous result.
        *args: Positional arguments to pass to `sync_fn`.
        **kwargs: Keyword arguments to pass to `sync_fn`.

    Returns:
        The result of `sync_fn` invocation. If the result is awaitable, the
        awaited value is returned. Otherwise, the synchronous result is
        returned.
    """
    result = fn(*args, **kwargs)
    if isawaitable(result):
        return cast("T", await result)
    return result
Executes a callable function and handles both synchronous and asynchronous
    results.

    This function invokes the provided callable `sync_fn` with the given
    arguments and keyword arguments. If the result of `sync_fn` is awaitable,
    it awaits the result before returning it. Otherwise, the result is returned
    directly.

    Args:
        fn: The callable to be executed. It can produce either a
            synchronous or asynchronous result.
        *args: Positional arguments to pass to `sync_fn`.
        **kwargs: Keyword arguments to pass to `sync_fn`.

    Returns:
        The result of `sync_fn` invocation. If the result is awaitable, the
        awaited value is returned. Otherwise, the synchronous result is
        returned.
    
kreuzberg/_utils/_sync.py