run method.
See more about Awaitables and tail calls.
The Future object can be used to get the result of the operation once it completes.
concurrent.futures.Future class in Python.
Class method Future.wait(futures: Iterable[Future], timeout: float|None = None, return_when=RETURN_WHEN.ALL_COMPLETED) -> None
can be used to wait for multiple Futures to complete. This class method is inspired by the standard concurrent.futures.wait in Python.
Example: Running multiple function calls in parallel
Waiting for multiple Futures to complete
Future.wait class method can be used to wait for multiple Futures to complete. This class method is inspired by the standard concurrent.futures.wait in Python.
It’s full signature is:
futures: An iterable of Future objects to wait for.timeout: An optional timeout in seconds. If specified, the method will return after the timeout even if not all Futures have completed.return_when: A flag indicating when to return. It can be one of the following values from theRETURN_WHENenum:RETURN_WHEN.ALL_COMPLETED: Wait until all Futures have completed.RETURN_WHEN.FIRST_COMPLETED: Wait until at least one Future has completed.RETURN_WHEN.FIRST_EXCEPTION: Wait until at least one Future has raised an exception or all have completed.
(done, not_done), where done is a list of Futures that have completed, and not_done is a list of Futures that have not completed yet.
Future object
Future object has the following methods and properties:id -> str: A unique identifier for the Future object in scope of the current application request.exception -> Exception|None: If the function call associated with this Future raised an exception, this property will return the exception object. Otherwise, it will returnNone. If the function call is not yet complete, this property will also returnNone.result(timeout: float|None = None) -> Any: Blocks until the Future completes and returns the result of the function call. If the function call raised an exception, theFunctionCallFailurewill be raised here. See more about error handling. An optional timeout in seconds can be specified. If timeout is reached before the Future completes, aTimeoutErrorwill be raised.done() -> bool: ReturnsTrueif the Future has completed (either successfully or with an exception), otherwise returnsFalse.