Template Class Future¶
Defined in File future.h
Nested Relationships¶
Nested Types¶
Class Documentation¶
-
template<typename T>
class Future¶ The result of one asynchronous operation, completed by a worker thread.
The completion is recorded in C++ only (a mutex and a condition variable), so the worker thread never needs the Python GIL; the threads that wait for the result convert it to Python. Copies of a future share its state.
The result is destroyed with the last copy of the future. A worker that holds a copy must release it on a thread that may run the result’s destructor (for example, one that may call a Python allocator’s deleter).
Tmust be copyable:getreturns a copy, so the result can be read any number of times, as withconcurrent.futures.Future.result().Public Functions
-
inline explicit Future(std::optional<CompletionQueue> queue = std::nullopt)¶
Creates a pending future. If
queueis given, the future’s ID is pushed to it on completion.
-
inline uint64_t id() const¶
Identifier unique within the process.
-
inline void set_result(T result)¶
Completes the future with a result. Later completions are ignored.
-
inline void set_error(std::exception_ptr error)¶
Completes the future with an error. Later completions are ignored. A null
erroris replaced with astd::runtime_error, so a completed future always holds either a result or an error.
-
inline bool done() const¶
Whether the future is completed.
-
inline bool wait(std::optional<double> timeout = std::nullopt) const¶
Waits until the future is completed, or until
timeoutseconds pass.nullopt(or a timeout too long to represent) waits indefinitely.- Returns:
Whether the future is completed.
-
inline std::exception_ptr exception() const¶
Waits for the future and returns its error, or nullptr if it succeeded.
-
inline explicit Future(std::optional<CompletionQueue> queue = std::nullopt)¶