| 5 | using namespace std::chrono_literals; |
| 6 | |
| 7 | int main() { |
| 8 | concurrencpp::runtime runtime; |
| 9 | std::atomic_size_t counter = 1; |
| 10 | concurrencpp::timer timer = runtime.timer_queue()->make_timer(1500ms, 2000ms, runtime.thread_pool_executor(), [&] { |
| 11 | const auto c = counter.fetch_add(1); |
| 12 | std::cout << "timer was invoked for the " << c << "th time" << std::endl; |
| 13 | }); |
| 14 | |
| 15 | std::cout << "timer due time (ms): " << timer.get_due_time().count() << std::endl; |
| 16 | std::cout << "timer frequency (ms): " << timer.get_frequency().count() << std::endl; |
| 17 | std::cout << "timer-associated executor : " << timer.get_executor()->name << std::endl; |
| 18 | |
| 19 | std::this_thread::sleep_for(20s); |
| 20 | |
| 21 | std::cout << "main thread cancelling timer" << std::endl; |
| 22 | timer.cancel(); |
| 23 | |
| 24 | std::this_thread::sleep_for(10s); |
| 25 | |
| 26 | return 0; |
| 27 | } |
nothing calls this directly
no test coverage detected