Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

# timercpp
Javascript like timer for c++ developers

This 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" <