from typing import Callable
from typing import Optional
from typing import Tuple
from typing import Any
from typing import Union
import time


def combined_timeout(
    func: Callable, timeout: Optional[float] = None
) -> Tuple[Any, Union[float, None]]:
    """Call func(timeout) and return reduced timeout for subsequent funcs.

    Args:
        func: A function with signature func(timeout).
        timeout: The time to wait for function call.

    Returns:
        A pair of the function return and the updated timeout variable
        for remaining time left to wait for other functions.
    """
    time_start = time.time()
    ret = func(timeout)
    time_stop = time.time()
    if timeout is not None:
        timeout = max(0, timeout + time_start - time_stop)
    return ret, timeout