Future

class Future[source]

Bases: object

Future is used for representing an asynchronous computation result.

set_result(result)[source]

Sets the result of the Future.

Parameters

result – Result of the Future.

set_exception(exception, traceback=None)[source]

Sets the exception for this Future in case of errors.

Parameters
  • exception (Exception) – Exception to be threw in case of error.

  • traceback (types.TracebackType) – Traceback of the exception.

result()[source]

Returns the result of the Future, which makes the call synchronous if the result has not been computed yet.

Returns

Result of the Future.

is_success()[source]

Determines whether the result can be successfully computed or not.

done()[source]

Determines whether the result is computed or not.

Returns

True if the result is computed, False otherwise.

Return type

bool

running()[source]

Determines whether the asynchronous call, the computation is still running or not.

Returns

True if the result is being computed, False otherwise.

Return type

bool

exception()[source]

Returns the exceptional result, if any.

Returns

Exception of this Future.

Return type

Exception

traceback()[source]

Traceback of the exception.

add_done_callback(callback)[source]
continue_with(continuation_func, *args)[source]

Create a continuation that executes when the Future is completed.

Parameters
  • continuation_func (function) – A function which takes the Future as the only parameter. Return value of the function will be set as the result of the continuation future. If the return value of the function is another Future, it will be chained to the returned Future.

  • *args – Arguments to be passed into continuation_function.

Returns

A new Future which will be completed when the continuation is done.

Return type

Future

combine_futures(futures)[source]

Combines set of Futures.

It waits for the completion of the all input Futures regardless of their output.

The returned Future completes with the list of the results of the input Futures, respecting the input order.

If one of the input Futures completes exceptionally, the returned Future also completes exceptionally. In case of multiple exceptional completions, the returned Future will be completed with the first exceptional result.

Parameters

futures (list[Future]) – List of Futures to be combined.

Returns

Result of the combination.

Return type

Future