24#ifndef ROUTER_SRC_ROUTER_INCLUDE_HELPER_WAIT_VARIABLE_H_
25#define ROUTER_SRC_ROUTER_INCLUDE_HELPER_WAIT_VARIABLE_H_
27#include <initializer_list>
33template <
typename ValueType>
44 template <
typename Container = std::initializer_list<ValueType>,
45 typename Callback = DoNothing>
46 bool exchange(
const Container &expected,
const ValueType &v,
50 [&expected, &v, &after_set_callback, &
result](
auto &value,
auto &cv) {
62 template <
typename Callback = DoNothing>
63 bool exchange(
const ValueType &expected,
const ValueType &v,
67 [&expected, &v, &after_set_callback, &
result](
auto &value,
auto &cv) {
68 if (expected == value) {
79 template <
typename Callback = DoNothing>
83 [&
result, &after_get_callback](
auto ¤t_value,
auto &) {
91 template <
typename Callback = DoNothing>
92 void set(
const ValueType &v,
95 [&v, &after_set_callback](
auto &value,
auto &cv) {
102 template <
typename Callback>
105 [&set_callback](
auto &value,
auto &cv) {
111 template <
typename Callback = DoNothing>
112 bool is(std::initializer_list<ValueType> expected_values,
116 [
this, &
result, &expected_values, &after_is_callback](
117 auto ¤t_value,
auto &) {
119 if (
result) after_is_callback();
124 template <
typename Callback = DoNothing>
125 bool is(
const ValueType &expected_value,
129 [&
result, &expected_value, &after_is_callback](
auto ¤t_value,
131 result = (expected_value == current_value);
132 if (
result) after_is_callback();
137 template <
typename Callback = DoNothing>
138 void wait(
const ValueType &expected_value,
141 [&expected_value, &callback](
const auto ¤t_value) {
142 if (expected_value == current_value) {
150 template <
typename Callback = DoNothing>
151 ValueType
wait(std::initializer_list<ValueType> expected_values,
155 [&expected_values, &callback, &
result](
const auto ¤t_value) {
167 template <
class Rep,
class Period,
typename Callback = DoNothing>
168 bool wait_for(
const std::chrono::duration<Rep, Period> &rel_time,
169 const ValueType &expected_value,
172 rel_time, [
this, expected_value, &callback](
auto ¤t_value) {
173 if (current_value == expected_value) {
181 template <
class Rep,
class Period,
typename Callback = DoNothing>
183 const std::chrono::duration<Rep, Period> &rel_time,
184 std::initializer_list<ValueType> expected_values,
188 rel_time, [
this, &expected_values, &
result,
189 &callback](
const auto ¤t_value) {
190 if (helper::container::has(expected_values, current_value)) {
191 result = current_value;
Class that stores callback function reference as well as the result of the callback function call (in...
Definition: keyring_service.cc:43
Monitor can be waited for.
Definition: monitor.h:62
Definition: wait_variable.h:39
void operator()() const
Definition: wait_variable.h:41
Definition: wait_variable.h:34
WaitableMonitor< ValueType > monitor_with_value_
Definition: wait_variable.h:204
bool is(std::initializer_list< ValueType > expected_values, const Callback &after_is_callback=Callback())
Definition: wait_variable.h:112
void change(const Callback &set_callback)
Definition: wait_variable.h:103
WaitableVariable()
Definition: wait_variable.h:36
WaitableVariable(const ValueType &value)
Definition: wait_variable.h:37
ValueType get(const Callback &after_get_callback=DoNothing())
Definition: wait_variable.h:80
void wait(const ValueType &expected_value, const Callback &callback=Callback())
Definition: wait_variable.h:138
ValueType wait(std::initializer_list< ValueType > expected_values, const Callback &callback=Callback())
Definition: wait_variable.h:151
stdx::expected< ValueType, bool > wait_for(const std::chrono::duration< Rep, Period > &rel_time, std::initializer_list< ValueType > expected_values, const Callback &callback=Callback())
Definition: wait_variable.h:182
bool exchange(const Container &expected, const ValueType &v, const Callback &after_set_callback=DoNothing())
Definition: wait_variable.h:46
bool is(const ValueType &expected_value, const Callback &after_is_callback=Callback())
Definition: wait_variable.h:125
bool wait_for(const std::chrono::duration< Rep, Period > &rel_time, const ValueType &expected_value, const Callback &callback=Callback())
Definition: wait_variable.h:168
bool exchange(const ValueType &expected, const ValueType &v, const Callback &after_set_callback=DoNothing())
Definition: wait_variable.h:63
void set(const ValueType &v, const Callback &after_set_callback=DoNothing())
Definition: wait_variable.h:92
Definition: expected.h:286
bool has(const Container &c, Value &&val)
Definition: generic.h:97
constexpr unexpect_t unexpect
Definition: expected.h:109
struct result result
Definition: result.h:34