24#ifndef MYSQL_HARNESS_UTILITY_WAIT_VARIABLE_H_
25#define MYSQL_HARNESS_UTILITY_WAIT_VARIABLE_H_
27#include <initializer_list>
36template <
typename ValueType>
47 template <
typename Container = std::initializer_list<ValueType>,
48 typename Callback = DoNothing>
49 bool exchange(
const Container &expected,
const ValueType &v,
53 [&expected, &v, &after_set_callback, &
result](
auto &
value,
auto &cv) {
65 template <
typename Callback = DoNothing>
66 bool exchange(
const ValueType &expected,
const ValueType &v,
70 [&expected, &v, &after_set_callback, &
result](
auto &
value,
auto &cv) {
71 if (expected ==
value) {
82 template <
typename Callback = DoNothing>
86 [&
result, &after_get_callback](
auto ¤t_value,
auto &) {
94 template <
typename Callback = DoNothing>
95 void set(
const ValueType &v,
98 [&v, &after_set_callback](
auto &
value,
auto &cv) {
100 after_set_callback();
105 template <
typename Callback>
108 [&set_callback](
auto &
value,
auto &cv) {
114 template <
typename Callback = DoNothing>
115 bool is(std::initializer_list<ValueType> expected_values,
119 [&
result, &expected_values, &after_is_callback](
auto ¤t_value,
123 if (
result) after_is_callback();
128 template <
typename Callback = DoNothing>
129 bool is(
const ValueType &expected_value,
133 [&
result, &expected_value, &after_is_callback](
auto ¤t_value,
135 result = (expected_value == current_value);
136 if (
result) after_is_callback();
141 template <
typename Callback = DoNothing>
142 void wait(
const ValueType &expected_value,
145 [&expected_value, &callback](
const auto ¤t_value) {
146 if (expected_value == current_value) {
154 template <
typename Callback = DoNothing>
155 ValueType
wait(std::initializer_list<ValueType> expected_values,
159 [&expected_values, &callback, &
result](
const auto ¤t_value) {
172 template <
class Rep,
class Period,
typename Callback = DoNothing>
173 bool wait_for(
const std::chrono::duration<Rep, Period> &rel_time,
174 const ValueType &expected_value,
177 rel_time, [&expected_value, &callback](
auto ¤t_value) {
178 if (current_value == expected_value) {
186 template <
class Rep,
class Period,
typename Callback = DoNothing>
188 const std::chrono::duration<Rep, Period> &rel_time,
189 std::initializer_list<ValueType> expected_values,
194 [&expected_values, &
result, &callback](
const auto ¤t_value) {
195 if (mysql_harness::utility::container::has(expected_values,
197 result = current_value;
Class that stores callback function reference as well as the result of the callback function call (in...
Definition: keyring_service.cc:44
Monitor can be waited for.
Definition: monitor.h:62
Definition: wait_variable.h:42
void operator()() const
Definition: wait_variable.h:44
Definition: wait_variable.h:37
bool is(const ValueType &expected_value, const Callback &after_is_callback=Callback())
Definition: wait_variable.h:129
void set(const ValueType &v, const Callback &after_set_callback=DoNothing())
Definition: wait_variable.h:95
bool wait_for(const std::chrono::duration< Rep, Period > &rel_time, const ValueType &expected_value, const Callback &callback=Callback())
Definition: wait_variable.h:173
void change(const Callback &set_callback)
Definition: wait_variable.h:106
bool exchange(const ValueType &expected, const ValueType &v, const Callback &after_set_callback=DoNothing())
Definition: wait_variable.h:66
WaitableVariable()
Definition: wait_variable.h:39
ValueType wait(std::initializer_list< ValueType > expected_values, const Callback &callback=Callback())
Definition: wait_variable.h:155
bool exchange(const Container &expected, const ValueType &v, const Callback &after_set_callback=DoNothing())
Definition: wait_variable.h:49
void wait(const ValueType &expected_value, const Callback &callback=Callback())
Definition: wait_variable.h:142
WaitableVariable(const ValueType &value)
Definition: wait_variable.h:40
WaitableMonitor< ValueType > monitor_with_value_
Definition: wait_variable.h:210
ValueType get(const Callback &after_get_callback=DoNothing()) const
Definition: wait_variable.h:83
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:187
bool is(std::initializer_list< ValueType > expected_values, const Callback &after_is_callback=Callback())
Definition: wait_variable.h:115
Definition: expected.h:286
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
bool has(const Container &c, Value &&val)
Definition: generic.h:89
unexpected(E) -> unexpected< E >
struct result result
Definition: result.h:34