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 has already completed, it cannot be cancelled and this method returns False. Otherwise, this method cancels the future (if it wasn’t cancelled already) and returns True.

Returns:

True if this future is cancelled, False if it has completed.

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 has neither completed nor been cancelled, 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. A timeout of 0 returns immediately (a non-blocking poll), raising Ice.TimeoutException if the result is not yet available.

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. A timeout of 0 returns immediately (a non-blocking poll), raising Ice.TimeoutException if the operation has not yet completed.

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]

Returns a new Future already completed with the given result.

Parameters:

result (_T)

Return type:

Future[_T]

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