/** * @file Timer.h * @author apio (cloudapio.eu) * @brief Millisecond-precision timer. * * @copyright Copyright (c) 2024, the Luna authors. * */ #pragma once #include #include #include #include namespace os { class EventLoop; class Timer : LinkedListNode { public: static Result> create_singleshot(unsigned int milliseconds, Action&& action); static Result> create_repeating(unsigned int milliseconds, Action&& action); ~Timer(); private: timer_t m_timerid { -1 }; bool m_repeating; struct timespec m_interval; Action m_action; void check_if_should_invoke_action(); Timer() = default; friend class EventLoop; }; }