template<typename T,
ReturnValuePolicy policy = std::is_void_v<typename std::remove_reference_t<T>::value_type> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
class pw::async2::FutureTask< T, policy >
Creates a task that pends a future until it completes.
FutureTask can be initialized in a few ways:
- Default construct:
FutureTask<MyFuture> task
- Move a future:
FutureTask task(std::move(future))
- Construct a future in place:
FutureTask<MyFuture> task(arg1, arg2)
- Refer to an existing future:
FutureTask<MyFuture&> task(future)
A FutureTask that owns its future can be assigned a new future when the task is not registered with a Dispatcher:
- Assign a future:
task = std::move(future)
- Construct a future in place:
task.emplace_future(arg1, arg2)
- Reset to an empty future:
task.reset()
The future's return value is stored and can be accessed through value() after joining, or by calling Wait(). For futures returning void, the return value is discarded by default (ReturnValuePolicy::kDiscard). To discard the return value futures returning non-void, specify ReturnValuePolicy::kDiscard.
- Warning
FutureTask is intended for test and occasional production use. A FutureTask does not contain logic, and relying too much on FutureTasks could push logic out of async tasks, which nullifies the benefits of pw_async2. Creating a task for each future is also less efficient than having one task work with multiple futures.
|
| template<typename U = T, typename = std::enable_if_t<!std::is_reference_v<U>>> |
| constexpr | FutureTask () |
| |
| template<typename Arg = T, typename... Args, typename = std::enable_if_t< !std::is_same_v<std::remove_cv_t<std::remove_reference_t<Arg>>, FutureTask> && std::is_constructible_v<T, Arg, Args...>>> |
| constexpr | FutureTask (Arg &&arg, Args &&... args) |
| |
|
| FutureTask (const FutureTask &)=delete |
| |
|
FutureTask & | operator= (const FutureTask &)=delete |
| |
|
| FutureTask (FutureTask &&)=delete |
| |
|
FutureTask & | operator= (FutureTask &&)=delete |
| |
| template<typename U = T, typename = std::enable_if_t< !std::is_same_v<std::remove_cv_t<std::remove_reference_t<U>>, FutureTask> && !std::is_reference_v<T> && std::is_assignable_v<T&, U>>> |
| FutureTask & | operator= (U &&future) |
| |
| template<typename... Args, typename = std::enable_if_t<!std::is_reference_v<T> && std::is_constructible_v<T, Args...>>> |
| void | emplace_future (Args &&... args) |
| |
| template<typename U = T, typename = std::enable_if_t<!std::is_reference_v<U>>> |
| void | reset () |
| |
| constexpr bool | is_pendable () const |
| |
|
constexpr bool | is_complete () const |
| | Returns whether the inner future has completed.
|
| |
| constexpr bool | has_value () const |
| |
| Poll< value_type > | TakePoll () |
| |
| FutureValue< future_type > & | value () & |
| |
| const FutureValue< future_type > & | value () const & |
| |
| FutureValue< future_type > && | value () && |
| |
| const FutureValue< future_type > && | value () const && |
| |
| FutureValue< future_type > & | Wait () |
| |
| constexpr | Task (log::Token name=kDefaultName) |
| |
|
| Task (const Task &)=delete |
| |
|
| Task (Task &&)=delete |
| |
|
Task & | operator= (const Task &)=delete |
| |
|
Task & | operator= (Task &&)=delete |
| |
| virtual | ~Task () |
| |
| Poll | Pend (Context &cx) |
| |
| bool | IsRegistered () const |
| |
| void | Deregister () |
| |
| void | BlockingJoin () |
| |
template<typename T ,
ReturnValuePolicy policy = std::is_void_v<typename std::remove_reference_t<T>::value_type> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
template<typename Arg = T, typename... Args, typename = std::enable_if_t< !std::is_same_v<std::remove_cv_t<std::remove_reference_t<Arg>>, FutureTask> && std::is_constructible_v<T, Arg, Args...>>>
Constructs a FutureTask. Forwards arguments to the future's constructor for FutureTasks that own their future. Reference FutureTasks take a mutable reference to their future.
template<typename T ,
ReturnValuePolicy policy = std::is_void_v<typename std::remove_reference_t<T>::value_type> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
|
|
inlineoverrideprivatevirtual |
Attempts to advance this Task to completion.
This method should not perform synchronous waiting, as doing so may block the main Dispatcher loop and prevent other Task s from progressing. Because of this, Task s should not invoke blocking Dispatcher methods such as RunUntilComplete.
Tasks should also avoid invoking RunUntilStalled on their own Dispatcher.
Returns Ready if complete, or Pending if the Task was not yet able to complete.
If Pending is returned, the Task must ensure it is woken up when it is able to make progress. To do this, Task::Pend must arrange for Waker::Wake to be called, either by storing a copy of the Waker away to be awoken by another system (such as an interrupt handler).
Implements pw::async2::Task.