Skip to content

taps.future

Utilities for type checking third-party future types.

FutureProtocol

Bases: Protocol[ResultT]

Future protocol.

This Protocol is useful for type checking future types that do not inherit from Future (such as Dask's Future).

This protocol does not require running() because Dask does not provide that method.

add_done_callback

add_done_callback(
    callback: Callable[[FutureProtocol[ResultT]], Any]
) -> None

Add a done callback to the future.

Source code in taps/future.py
def add_done_callback(
    self,
    callback: Callable[[FutureProtocol[ResultT]], Any],
) -> None:
    """Add a done callback to the future."""
    ...

cancel

cancel() -> bool

Attempt to cancel the task.

Source code in taps/future.py
def cancel(self) -> bool:
    """Attempt to cancel the task."""
    ...

cancelled

cancelled() -> bool

Check if the task was cancelled.

Source code in taps/future.py
def cancelled(self) -> bool:
    """Check if the task was cancelled."""
    ...

done

done() -> bool

Check if the task is done.

Source code in taps/future.py
def done(self) -> bool:
    """Check if the task is done."""
    ...

exception

exception(
    timeout: float | None = None,
) -> BaseException | None

Get the exception raised by the task.

Source code in taps/future.py
def exception(self, timeout: float | None = None) -> BaseException | None:
    """Get the exception raised by the task."""
    ...

result

result(timeout: float | None = None) -> ResultT

Get the result of the task.

Source code in taps/future.py
def result(self, timeout: float | None = None) -> ResultT:
    """Get the result of the task."""
    ...

is_future

is_future(obj: Any) -> bool

Check if an object is future-like.

Source code in taps/future.py
def is_future(obj: Any) -> bool:
    """Check if an object is future-like."""
    return isinstance(obj, FutureProtocol)