16 #include <condition_variable> 26 periodic_worker(
const std::function<
void()> &callback_fun, std::chrono::seconds interval)
28 active_ = (interval > std::chrono::seconds::zero());
34 worker_thread_ = std::thread([
this, callback_fun, interval]() {
37 std::unique_lock<std::mutex> lock(this->mutex_);
38 if (this->cv_.wait_for(lock, interval, [
this] { return !this->active_; }))
53 if (worker_thread_.joinable())
56 std::lock_guard<std::mutex> lock(mutex_);
60 worker_thread_.join();
66 std::thread worker_thread_;
68 std::condition_variable cv_;
periodic_worker(const std::function< void()> &callback_fun, std::chrono::seconds interval)
periodic_worker & operator=(const periodic_worker &)=delete