Skip to content

ngruenwald/tempus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TEMPUS

timer stuff

tempus::timer_queue

The timer_queue implementation is sourced from http://www.crazygaze.com/blog/2016/03/24/portable-c-timer-queue/

Usage

using clock = std::chrono::high_resolution_clock;

tempus::timer_queue tiqu;

tiqu.add(
  100,                                        // timeout in milliseconds
  [auto start = clock::now()](bool aborted)   // handler function
  {
    std::cout
      << "aborted: " << aborted << std::endl
      << "elapsed: " << elapsed(start, clock::now()) << " ms" << std::endl;
  }
);

tiqu.add(
  1000,                                       // timeout in milliseconds
  [auto start = clock::now()](bool aborted)   // handler function
  {
    std::cout
      << "aborted: " << aborted << std::endl
      << "elapsed: " << elapsed(start, clock::now()) << " ms" << std::endl;
  }
);

std::this_thread::sleep_for(std::chrono::milliseconds(500));

tiqu.cancel_all();
aborted: 0
elapsed: 100 ms
aborted: 1
elapsed: 500 ms