// // Created by xtkuang on 2025/5/14. // #ifndef CMVR_ES_TIMER_H #define CMVR_ES_TIMER_H #include #include #include #include #include #include #include #include #include class FDTimer { public: using Callback = std::function; FDTimer(); ~FDTimer(); void start(std::chrono::nanoseconds interval, Callback callback); void stop(); [[nodiscard]] bool is_running() const; private: static timespec toTimespec(std::chrono::nanoseconds ns); int fd_; std::atomic running_; Callback callback_; std::thread worker_thread_; }; #endif //CMVR_ES_TIMER_H