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 returnsTrue.- Returns:
Trueif this future is cancelled,Falseif it has completed.- 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 has neither completed nor been cancelled, 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. A timeout of0returns immediately (a non-blocking poll), raisingIce.TimeoutExceptionif the result is not yet available.- 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.
BaseException – The exception raised by the operation, if any.
- 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 of0returns immediately (a non-blocking poll), raisingIce.TimeoutExceptionif the operation has not yet completed.- 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.
- 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'¶