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:
Trueif this future was cancelled,Falseotherwise.- Return type:
- cancelled() bool¶
Checks if this future has been cancelled.
- Returns:
Trueif this future was cancelled, otherwiseFalse.- Return type:
- running() bool¶
Checks if this future is still running.
- Returns:
Trueif this future is currently executing, otherwiseFalse.- Return type:
- done() bool¶
Checks if this future has completed or been cancelled.
- Returns:
Trueif this future has completed (either successfully or with an exception), or has been cancelled, otherwiseFalse.- Return type:
- 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,
fnis 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:
- Raises:
TimeoutException – If the operation has not completed within the specified timeout.
InvocationCanceledException – If the operation was cancelled before completing.
Exception – If the operation raised an exception.
- 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
Noneif the operation completed successfully.- Return type:
BaseException | None
- Raises:
TimeoutException – If the operation has not completed within the specified timeout.
InvocationCanceledException – If the operation was cancelled before completing.
- set_result(result: _T)¶
Sets the result of this future and marks it as completed.
This function stores the provided
resultand 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
exand 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.
- StateRunning = 'running'¶
- StateCancelled = 'cancelled'¶
- StateDone = 'done'¶