Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
pw::async2::Selector< Pendables > Class Template Reference

Public Types

using ResultVariant = typename internal::SelectVariantType< std::make_index_sequence< sizeof...(Pendables)>, Pendables... >::type
 

Public Member Functions

 Selector (Pendables &&... pendables)
 Creates a SingleSelector from a series of pendable values.
 
Poll< ResultVariant > Pend (Context &cx)
 

Detailed Description

template<typename... Pendables>
class pw::async2::Selector< Pendables >

A pendable value which returns the result of the first of several pendable values to complete.

Each call to Selector::Pend polls its pendables until one returns Ready. If a Ready pendable is found, its value is returned as a SelectResult indicating the index of the completed pendable.

If no pendables are Ready, Selector::Pend returns a Pending.

If every pendable provided to the Selector has already completed, Pend will return an AllPendablesCompleted value indicating this.

Example usage:

Poll<int> TaskOne(Context&) { return Ready(3); }
Poll<char> TaskTwo(Context&) { return Ready('c'); }
Poll<> RaceTasks(Context& cx) {
auto task_one = PendableFor<&TaskOne>();
auto task_two = PendableFor<&TaskTwo>();
Selector selector(std::move(task_one), std::move(task_two));
auto result = selector.Pend(cx);
if (result.IsPending()) {
return Pending();
}
VisitSelectResult(
*result,
[](AllPendablesCompleted) { PW_LOG_INFO("Both tasks completed"); },
[](int value) {
PW_LOG_INFO("Task one completed with value %d", value);
},
[](char value) {
PW_LOG_INFO("Task two completed with value %c", value);
});
}
Definition: context.h:49
Definition: poll.h:54

Member Function Documentation

◆ Pend()

template<typename... Pendables>
Poll< ResultVariant > pw::async2::Selector< Pendables >::Pend ( Context cx)
inline

Attempts to complete the stored pendables, returning the first one which is ready.


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