Periodic Timer
Loading...
Searching...
No Matches
periodic_timer_example.cpp File Reference

Example code demonstrating use of chops::periodic_timer. More...

#include <iostream>
#include <cstdlib>
#include <chrono>
#include <thread>
#include "asio/executor_work_guard.hpp"
#include "asio/executor.hpp"
#include "timer/periodic_timer.hpp"
Include dependency graph for periodic_timer_example.cpp:

Functions

int main ()
 The chops::periodic_timer calls a user supplied callback function at a user defined interval. The callback funtion is repeatedly called while it returns true, but the timer terminates when the function returns false.
 

Detailed Description

Example code demonstrating use of chops::periodic_timer.

Author
Thurman Gillespy

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Sample make file: g++ -std=c++17 -I ~/Projects/utility-rack/include/ \ -I ~/Projects/asio/asio/include/ \ -I ~/Projects/ timer_demo.cpp -lpthread

This also builds with CMake files with C++ 20 specified

Function Documentation

◆ main()

int main ( )

The chops::periodic_timer calls a user supplied callback function at a user defined interval. The callback funtion is repeatedly called while it returns true, but the timer terminates when the function returns false.

The timer executes inside an std::thread. The thread and timer are linked with an asio::io_context. As the example shows, multiple timers can be run inside one thread. An asio::executor_work_guard controls ownership of executor work within the thread. Without either the thread or the exector_work_guard, the timer will not execute.