You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Simple library to repeatedly call a member function, free function or lambda at a given time interval.
Features
Use a variety of callback types:
Class member functions via std::bind
Free functions
Lambdas
RAII cleanup, don't have to worry about explicitly calling stop().
Reliable function timing (tested to be within ~1 millisecond)
Auto-recovery if callback takes longer than interval time.
Usage
#include<periodic_function/periodic_function.hpp>// call function every 300 milliseconds
dp::periodic_function heartbeat([]() {
// do something here...
}, 300U);
// start calling function
heartbeat.start();
// optional: stop calling the function// function will stop being called when object goes out of scope
heartbeat.stop();
Customization Points
Handling Callbacks that Exceed the Timer Interval
How callbacks that exceed the interval are handled is passed on a template argument policy class. The current policies available are:
schedule_next_missed_interval_policy (default)
This will schedule the callback to be called again on the next interval timeout (the interval that was missed is skipped). This is good to use if the callback is not expected to exceed the interval time.
invoke_immediately_missed_interval_policy
This will schedule the callback to be called immediately and then control will be given back to the timer which will operate at the regular interval.
Building
periodic-functionrequires C++17 support and has been tested with: