Demonstrates the use of different timers and basic use the the EventHAndler class.
#include <chrono>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
int main()
{
std::cout << "one-shot timer fired\n";
});
const auto heartbeat = events.
addPeriodicTimer(500ms, [](std::uint64_t expirations) {
std::cout << "heartbeat (" << expirations << " expiration)\n";
});
int tick = 0;
const int current = ++tick;
std::cout << "timer fired: " << current << '\n';
events.
defer([&, current] {
std::cout << " deferred work for tick " << current << '\n';
});
});
std::thread shutdown([&events] {
std::this_thread::sleep_for(1100ms);
});
try {
} catch (...) {
shutdown.join();
throw;
}
shutdown.join();
std::cout << "event loop exited\n";
return 0;
}
void defer(std::function< void()> callback)
void removeTimer(TimerId id)
void restartTimer(TimerId id)
TimerId addOneShotTimer(std::chrono::milliseconds delay, TimerCallback callback)
TimerId addPeriodicTimer(std::chrono::milliseconds interval, TimerCallback callback)