Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DeveloperPaul123/periodic-function
Small header only library to call a function at a specific time interval.
https://github.com/DeveloperPaul123/periodic-function
c-plus-plus c-plus-plus-17 callback cpp cpp-library cpp17 cross-platform header-library header-only lambdas library lightweight modern-cpp no-dependencies periodic-jobs periodic-tasks single-header-lib
Last synced: 2 months ago
JSON representation
Small header only library to call a function at a specific time interval.
- Host: GitHub
- URL: https://github.com/DeveloperPaul123/periodic-function
- Owner: DeveloperPaul123
- License: mit
- Created: 2020-04-15T01:10:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-26T17:46:43.000Z (over 2 years ago)
- Last Synced: 2024-05-01T13:57:10.871Z (8 months ago)
- Topics: c-plus-plus, c-plus-plus-17, callback, cpp, cpp-library, cpp17, cross-platform, header-library, header-only, lambdas, library, lightweight, modern-cpp, no-dependencies, periodic-jobs, periodic-tasks, single-header-lib
- Language: CMake
- Homepage:
- Size: 54.7 KB
- Stars: 24
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesomecpp - periodic-function - - small header only library to call a function at a specific time interval. (Scheduling)
README
periodic-function[![say thanks](https://img.shields.io/badge/Say%20Thanks-👍-1EAEDB.svg)](https://github.com/DeveloperPaul123/periodic-function/stargazers)
[![Discord](https://img.shields.io/discord/652515194572111872)](https://discord.gg/CX2ybByRnt)[![Actions Status](https://github.com/DeveloperPaul123/periodic-function/workflows/MacOS/badge.svg)](https://github.com/DeveloperPaul123/periodic-function/actions)
[![Actions Status](https://github.com/DeveloperPaul123/periodic-function/workflows/Windows/badge.svg)](https://github.com/DeveloperPaul123/periodic-function/actions)
[![Actions Status](https://github.com/DeveloperPaul123/periodic-function/workflows/Ubuntu/badge.svg)](https://github.com/DeveloperPaul123/periodic-function/actions)
[![Actions Status](https://github.com/DeveloperPaul123/periodic-function/workflows/Ubuntu-20.04/badge.svg)](https://github.com/DeveloperPaul123/periodic-function/actions)
[![Actions Status](https://github.com/DeveloperPaul123/periodic-function/workflows/Style/badge.svg)](https://github.com/DeveloperPaul123/periodic-function/actions)
[![Actions Status](https://github.com/DeveloperPaul123/periodic-function/workflows/Install/badge.svg)](https://github.com/DeveloperPaul123/periodic-function/actions)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
```cpp
#include// 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-function` **requires** C++17 support and has been tested with:
* Visual Studio 2019 (msvc)
* Visual Studio 2019 (clang-cl)
* Ubuntu 18/20.04 GCC 10
* Ubuntu 18/20.04 Clang 10Use the following commands to build the project
```bash
cmake -S -B build
cmake --build build --config Release
```To run tests, simple `cd` into the build directory and run:
```bash
ctest --build-config Debug
```## Contributing
Contributions are very welcome. Please see [contribution guidelines for more info](CONTRIBUTING.md).
## License
The project is licensed under the MIT license. See [LICENSE](LICENSE) for more details.
## Author
| [
@DeveloperPaul123](https://github.com/DeveloperPaul123) |
|:----:|### WIP Items
:construction: MacOS support is still a WIP. :construction: