Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/99x/timercpp
Javascript like setTimeout and setInterval for c++ developers
https://github.com/99x/timercpp
cpp cpp14 header-only setinterval settimeout
Last synced: 25 days ago
JSON representation
Javascript like setTimeout and setInterval for c++ developers
- Host: GitHub
- URL: https://github.com/99x/timercpp
- Owner: 99x
- License: mit
- Created: 2018-10-24T07:32:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-08T23:48:37.000Z (about 2 years ago)
- Last Synced: 2024-10-04T18:05:51.496Z (about 1 month ago)
- Topics: cpp, cpp14, header-only, setinterval, settimeout
- Language: C++
- Homepage:
- Size: 11.7 KB
- Stars: 246
- Watchers: 10
- Forks: 76
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timercpp
Javascript like timer for c++ developersThis header only library has js equivalent `setTimeout()` and `setInterval()` for c++.
**DISCLAIMER - This implementation uses threads not a queue**
## `setTimeout(auto function, int delay)`
```c++
Timer t = Timer();
t.setTimeout([&]() {
cout << "Hey.. After 1s." << endl;
}, 1000);
```## `setInterval(auto function, int interval)`
```c++
Timer t = Timer();
t.setInterval([&]() {
cout << "Hey.. After each 1s..." << endl;
}, 1000);
```## Sample Program
```c++
#include
#include "timercpp.h"using namespace std;
int main() {
Timer t = Timer();t.setInterval([&]() {
cout << "Hey.. After each 1s..." << endl;
}, 1000);t.setTimeout([&]() {
cout << "Hey.. After 5.2s. But I will stop the timer!" << endl;
t.stop();
}, 5200);
cout << "I am Timer" <