5 #ifndef IROHA_RUN_LOOP_HANDLER_HPP 6 #define IROHA_RUN_LOOP_HANDLER_HPP 9 #include <condition_variable> 11 #include <rxcpp/rx-lite.hpp> 14 namespace schedulers {
16 inline void handleEvents(rxcpp::composite_subscription &subscription,
17 rxcpp::schedulers::run_loop &run_loop) {
18 std::condition_variable wait_cv;
20 run_loop.set_notify_earlier_wakeup(
21 [&wait_cv](
const auto &) { wait_cv.notify_one(); });
23 std::mutex wait_mutex;
24 std::unique_lock<std::mutex> lock(wait_mutex);
25 while (subscription.is_subscribed() or not run_loop.empty()) {
26 while (not run_loop.empty()
27 and run_loop.peek().when <= run_loop.now()) {
31 if (run_loop.empty()) {
32 wait_cv.wait(lock, [&run_loop, &subscription]() {
33 return not subscription.is_subscribed() or not run_loop.empty();
36 wait_cv.wait_until(lock, run_loop.peek().when);
43 #endif // IROHA_RUN_LOOP_HANDLER_HPP Definition: block_query.hpp:15
void handleEvents(rxcpp::composite_subscription &subscription, rxcpp::schedulers::run_loop &run_loop)
Definition: run_loop_handler.hpp:16