Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Async & concurrency
  5. pw_async2
  6. Tasks
  7. pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard > Class Template Reference
pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard > Class Template Referencefinal

Overview

template<typename T>
class pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >

Specialization of FutureTask that discards the return value of the future.

Inheritance diagram for pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >:
pw::async2::internal::FutureTaskBase pw::async2::Task pw::IntrusiveQueue< T >::Item pw::async2::Context

Public Types

using future_type = std::remove_reference_t< T >
 The type of the future that is pended by this task.
 
using value_type = typename future_type::value_type
 The type produced by this tasks's future when it completes.
 

Public Member Functions

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.
 
- 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 BlockingJoin ()
 

Private Member Functions

Poll DoPend (Context &cx) override
 

Additional Inherited Members

- Protected Types inherited from pw::async2::Task
using Context = ::pw::async2::Context
 

Constructor & Destructor Documentation

◆ FutureTask() [1/2]

template<typename T >
template<typename U = T, typename = std::enable_if_t<!std::is_reference_v<U>>>
constexpr pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::FutureTask ( )
inlineconstexpr

Creates a FutureTask with a default-constructed future.

A default-constructed future is empty and cannot be pended (is_pendable() is false). A valid future must be assigned before this task is run by a Dispatcher, or Pend will crash.

◆ FutureTask() [2/2]

template<typename T >
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 pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::FutureTask ( Arg &&  arg,
Args &&...  args 
)
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.

Member Function Documentation

◆ DoPend()

template<typename T >
Poll pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::DoPend ( Context &  )
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.

◆ emplace_future()

template<typename T >
template<typename... Args, typename = std::enable_if_t<!std::is_reference_v<T> && std::is_constructible_v<T, Args...>>>
void pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::emplace_future ( Args &&...  args)
inline

Constructs a new future in place to be pended by this task, resetting any previous Poll result to Pending.

Precondition
The task MUST NOT be registered with a Dispatcher (!IsRegistered()).

◆ is_complete()

template<typename T >
constexpr bool pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::is_complete ( ) const
inlineconstexpr

Returns whether the inner future has completed.

◆ is_pendable()

template<typename T >
constexpr bool pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::is_pendable ( ) const
inlineconstexpr

Returns whether the inner future is pendable.

A default-constructed future or a completed future is not pendable.

◆ operator=()

template<typename T >
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 & pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::operator= ( U &&  future)
inline

Assigns a new future to be pended by this task, resetting any previous Poll result to Pending.

Precondition
The task MUST NOT be registered with a Dispatcher (!IsRegistered()).

◆ reset()

template<typename T >
template<typename U = T, typename = std::enable_if_t<!std::is_reference_v<U>>>
void pw::async2::FutureTask< T, ReturnValuePolicy::kDiscard >::reset ( )
inline

Resets the inner future to a default-constructed state and clears any previous Poll result.

Precondition
The task MUST NOT be registered with a Dispatcher (!IsRegistered()).

The documentation for this class was generated from the following file: