Skip to content

Future

Future

Source code in src/officialeye/_api/future.py
class Future:

    def __init__(self, context: Context, python_future: PythonFuture, /, *, afi_fork: AbstractFeedbackInterface):
        self._context = context
        self._future = python_future
        self._afi_fork = afi_fork

        self._afi_joined = False

    def cancel(self) -> bool:
        """
        Attempt to cancel the call.
        If the call is currently being executed and cannot be canceled, then the method will return False,
        otherwise the call will be canceled, and the method will return True.
        """
        return self._future.cancel()

    def cancelled(self) -> bool:
        """ Return True if the call was successfully canceled. """
        return self._future.cancelled()

    def running(self) -> bool:
        """ Return True if the call is currently being executed and cannot be canceled. """
        return self._future.running()

    def done(self) -> bool:
        """ Return True if the call was successfully canceled or finished running. """
        return self._future.done()

    def _afi_join(self):
        if not self._afi_joined:
            self._afi_joined = True
            # noinspection PyProtectedMember
            self._context._get_afi().join(self._afi_fork, self._future)

    def result(self, timeout: float | None = None) -> Any:
        """
        Return the value returned by the call. If the call hasn’t yet completed, then this method will wait up to timeout seconds.
        If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised. Timeout can be an int or float.
        If timeout is not specified or None, there is no limit to the wait time.

        If the future is canceled before completing, then CancelledError will be raised.

        If the call raised, this method will raise the same exception.
        """

        result = self._future.result(timeout=timeout)

        assert isinstance(result, IApiInterfaceImplementation), \
            "Every call to an internal API function should return a proper public API interface implementation"

        result.set_api_context(self._context)

        self._afi_join()

        return result

    def exception(self, timeout: float | None = None) -> Any:
        """
        Return the exception raised by the call.
        If the call hasn’t yet completed, then this method will wait up to timeout seconds.
        If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised.
        Timeout can be an int or float.
        If timeout is not specified or None, there is no limit to the wait time.

        If the future is canceled before completing, then CancelledError will be raised.

        If the call completed without raising, None is returned.
        """

        err = self._future.exception(timeout=timeout)

        self._afi_join()

        return err

cancel()

Attempt to cancel the call. If the call is currently being executed and cannot be canceled, then the method will return False, otherwise the call will be canceled, and the method will return True.

Source code in src/officialeye/_api/future.py
def cancel(self) -> bool:
    """
    Attempt to cancel the call.
    If the call is currently being executed and cannot be canceled, then the method will return False,
    otherwise the call will be canceled, and the method will return True.
    """
    return self._future.cancel()

cancelled()

Return True if the call was successfully canceled.

Source code in src/officialeye/_api/future.py
def cancelled(self) -> bool:
    """ Return True if the call was successfully canceled. """
    return self._future.cancelled()

done()

Return True if the call was successfully canceled or finished running.

Source code in src/officialeye/_api/future.py
def done(self) -> bool:
    """ Return True if the call was successfully canceled or finished running. """
    return self._future.done()

exception(timeout=None)

Return the exception raised by the call. If the call hasn’t yet completed, then this method will wait up to timeout seconds. If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised. Timeout can be an int or float. If timeout is not specified or None, there is no limit to the wait time.

If the future is canceled before completing, then CancelledError will be raised.

If the call completed without raising, None is returned.

Source code in src/officialeye/_api/future.py
def exception(self, timeout: float | None = None) -> Any:
    """
    Return the exception raised by the call.
    If the call hasn’t yet completed, then this method will wait up to timeout seconds.
    If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised.
    Timeout can be an int or float.
    If timeout is not specified or None, there is no limit to the wait time.

    If the future is canceled before completing, then CancelledError will be raised.

    If the call completed without raising, None is returned.
    """

    err = self._future.exception(timeout=timeout)

    self._afi_join()

    return err

result(timeout=None)

Return the value returned by the call. If the call hasn’t yet completed, then this method will wait up to timeout seconds. If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised. Timeout can be an int or float. If timeout is not specified or None, there is no limit to the wait time.

If the future is canceled before completing, then CancelledError will be raised.

If the call raised, this method will raise the same exception.

Source code in src/officialeye/_api/future.py
def result(self, timeout: float | None = None) -> Any:
    """
    Return the value returned by the call. If the call hasn’t yet completed, then this method will wait up to timeout seconds.
    If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised. Timeout can be an int or float.
    If timeout is not specified or None, there is no limit to the wait time.

    If the future is canceled before completing, then CancelledError will be raised.

    If the call raised, this method will raise the same exception.
    """

    result = self._future.result(timeout=timeout)

    assert isinstance(result, IApiInterfaceImplementation), \
        "Every call to an internal API function should return a proper public API interface implementation"

    result.set_api_context(self._context)

    self._afi_join()

    return result

running()

Return True if the call is currently being executed and cannot be canceled.

Source code in src/officialeye/_api/future.py
def running(self) -> bool:
    """ Return True if the call is currently being executed and cannot be canceled. """
    return self._future.running()