Skip to content

collielimabean/Timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Timer

Simple timer that on expiration executes a callback.

I created this because my initial pure C++11 implementation hogged CPU time as it just used a thread and checked if enough time had elapsed. This implementation wraps OS specific timer APIs in order to avoid effectively a worker thread in a spin loop.

Example

#include "Timer.h"
#include <ctime>
#include <iostream>

void Callback()
{
    time_t current = time(nullptr);
    std::cout << "Callback executed on " << std::ctime(&current) << std::endl;
}

int main()
{
    Timer t(Interval(1000), &Callback, true);
    t.Start();

    char x;
    std::cin >> x;

    return 0;
}

About

Simple timer that on expiration executes a callback.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages