|
MoveIt Pro API
Core Behaviors for MoveIt Pro
|
A future backed by an explicitly-owned std::jthread, for Behaviors that offload work to a background thread and poll for completion (e.g. in onRunning()).
More...
#include <threaded_future.hpp>
Public Member Functions | |
| ThreadedFuture ()=default | |
Constructs an empty, invalid future. Matches default-constructed std::future<T>. | |
| ThreadedFuture (ThreadedFuture &&) noexcept=default | |
| ThreadedFuture & | operator= (ThreadedFuture &&) noexcept=default |
| ThreadedFuture (const ThreadedFuture &)=delete | |
| ThreadedFuture & | operator= (const ThreadedFuture &)=delete |
| template<typename F , typename = std::enable_if_t<!std::is_same_v<std::remove_cvref_t<F>, ThreadedFuture>>> | |
| ThreadedFuture (F &&task) | |
Runs task on a newly-created thread and captures its result. | |
| bool | valid () const noexcept |
| template<typename Rep , typename Period > | |
| std::future_status | wait_for (const std::chrono::duration< Rep, Period > &timeout_duration) const |
| void | wait () const |
| T | get () |
A future backed by an explicitly-owned std::jthread, for Behaviors that offload work to a background thread and poll for completion (e.g. in onRunning()).
Deliberately mirrors the subset of std::future's interface (valid(), wait_for(), wait(), get()) that this pattern uses, so it is a drop-in replacement for the std::future<T> member that std::async returns.
Unlike std::async(std::launch::async, ...), whose thread is owned by an implementation-defined pool, the background thread here is a std::jthread owned directly by this object. Like the future returned by std::async, destroying (or reassigning) a ThreadedFuture while its task is still running blocks until the task finishes: the owned std::jthread joins in its own destructor and move-assignment.
ThreadedFuture is a class member and its task captures this (or references to sibling members), members declared after the ThreadedFuture are destroyed before it joins — declare the ThreadedFuture as the last member so the join runs before anything the task dereferences is torn down.| T | The type returned by the task. |
|
default |
Constructs an empty, invalid future. Matches default-constructed std::future<T>.
|
defaultnoexcept |
|
delete |
|
inlineexplicit |
Runs task on a newly-created thread and captures its result.
|
inline |
|
delete |
|
defaultnoexcept |
|
inlinenoexcept |
|
inline |
|
inline |