Creates a task that pends a future until it completes.
FutureTask can be initialized in a few ways:
FutureTask task(std::move(future))Construct a future in place:FutureTask<MyFuture> task(arg1, arg2)Refer to an existing future:FutureTask<MyFuture&> task(future)`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.
Public Member Functions | |
| template<typename Arg , typename... Args> | |
| constexpr | FutureTask (Arg &&arg, Args &&... args) |
| 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 () |
Public Member Functions inherited from pw::async2::Task | |
| 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 | Join () |
Private Member Functions | |
| Poll | DoPend (Context &cx) override |
Additional Inherited Members | |
Protected Member Functions inherited from pw::containers::future::IntrusiveList< T >::Item | |
| constexpr | Item ()=default |
|
inlineexplicitconstexpr |
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.
Requires at least one argument. Default constructed futures are not permitted since since they cannot be pended.
|
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.
|
inline |
Takes the Poll result from the most recent task run. This function is NOT thread safe. It cannot be called when the task may run on another thread.
|
inline |
Returns the value produced by the future.
|
inline |
Returns the value produced by the future.
|
inline |
Returns the value produced by the future.
|
inline |
Returns the value produced by the future.
|
inline |
Joins that task, blocking until the future completes, then returns a reference its value.