Ice.Future

class Ice.Future

Bases: Awaitable[_T]

A Future object representing the result of an asynchronous operation.

cancel() bool

Attempts to cancel this future.

If this future is already running or has completed, it cannot be cancelled.

Returns:

True if this future was cancelled, False otherwise.

Return type:

bool

cancelled() bool

Checks if this future has been cancelled.

Returns:

True if this future was cancelled, otherwise False.

Return type:

bool

running() bool

Checks if this future is still running.

Returns:

True if this future is currently executing, otherwise False.

Return type:

bool

done() bool

Checks if this future has completed or been cancelled.

Returns:

True if this future has completed (either successfully or with an exception), or has been cancelled, otherwise False.

Return type:

bool

add_done_callback(fn: Callable[[Future], Any]) None

Attaches a callback function which will be called when this future completes or is cancelled. If this future is already complete, fn is called immediately from the calling thread.

Parameters:

fn (Callable[[Future], Any]) – The function to execute upon completion.

Return type:

None

result(timeout: int | float | None = None) _T

Retrieves the result of this future’s operation.

If the operation has not completed, this function will wait up to timeout-many seconds for it to finish. If the operation raised an exception, this function raises the same exception.

Parameters:

timeout (int | float | None, optional) – Maximum time (in seconds) to wait for the result. If None (the default), this function waits indefinitely until the operation completes.

Returns:

The result of the operation.

Return type:

object

Raises:
exception(timeout: int | float | None = None) BaseException | None

Retrieves the exception raised by this future’s operation.

If the operation has not completed, this function will wait up to timeout-many seconds for it to finish.

Parameters:

timeout (int | float | None, optional) – Maximum time (in seconds) to wait for the exception. If None (the default), this function waits indefinitely until the operation completes.

Returns:

The exception raised by the operation, or None if the operation completed successfully.

Return type:

BaseException | None

Raises:
set_result(result: _T)

Sets the result of this future and marks it as completed.

This function stores the provided result and transitions the future’s state to “done”. Any registered callbacks are executed after the state update.

If the future is not in a running state, this function has no effect.

Parameters:

result (object) – The result value to store in the future.

set_exception(ex: BaseException)

Sets an exception for this future and marks it as completed.

This function stores the provided exception ex and transitions the future’s state to “done”. Any registered callbacks are executed after the state update.

If the future is not in a running state, this function has no effect.

Parameters:

ex (BaseException) – The exception to store in the future.

static completed(result: _T) Future[_T]
Parameters:

result (_T)

Return type:

Future[_T]

StateRunning = 'running'
StateCancelled = 'cancelled'
StateDone = 'done'