You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
801 B

#include <memory>
#include <vector>
#include <functional>
#include <limits.h>
class timer_handle {
unsigned long interval; // in milliseconds
double nextAt; // timestamp in milliseconds
//bool timeout; // replaced by interval
std::function<void()> callback;
class Scheduler {
std::shared_ptr<timer_handle> setTimeout(std::function<void()> callback, unsigned long delay);
std::shared_ptr<timer_handle> setInterval(std::function<void()> callback, unsigned long delay);
unsigned long getNext();
bool fireTimer(std::shared_ptr<timer_handle> timer, double now);
void fireTimers();
bool clearInterval(std::shared_ptr<timer_handle> timer);
std::vector<std::shared_ptr<timer_handle>> timers;