Future

class Future

Bases: object

Future is used for representing an asynchronous computation result.

set_result(result)

Sets the result of the Future.

Parameters

result – Result of the Future.

set_exception(exception, traceback=None)

Sets the exception for this Future in case of errors.

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

  • traceback (function) – Function to be called on traceback.

result()

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()

Determines whether the result can be successfully computed or not.

done()

Determines whether the result is computed or not.

Returns

True if the result is computed, False otherwise.

Return type

bool

running()

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()

Returns the exceptional result, if any.

Returns

Exception of this Future.

Return type

Exception

traceback()

Traceback function for the Future.

add_done_callback(callback)
continue_with(continuation_func, *args)

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)

Combines set of Futures.

Parameters

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

Returns

Result of the combination.

Return type

Future