Time
-
class Timer
Allows setting a duration and checking if it has timed out.
Public Functions
-
explicit Timer(int64_t duration_ms)
Constructs a Timer with the specified duration.
- Parameters:
duration_ms – Duration in milliseconds.
-
void reset()
Resets the timer, starting from the current time.
-
bool hasTimedOut() const
Checks if the timer has timed out.
- Returns:
True if the timer has timed out, false otherwise.
-
explicit Timer(int64_t duration_ms)
-
class Chronometer
Allows measuring durations using system time.
-
class Scheduler
Allows scheduling tasks to run after a delay or at regular intervals using PersistentWorker.
Public Functions
-
void schedule_once(int64_t delay_ms, const std::function<void()> &task)
Schedules a task to run once after a delay.
- Parameters:
delay_ms – Delay in milliseconds before the task is executed.
task – The task to execute.
-
void schedule_repeating(const std::string &name, int64_t interval_ms, const std::function<void()> &task)
Schedules a task to run repeatedly at fixed intervals.
- Parameters:
name – A unique name for the task.
interval_ms – The interval in milliseconds between executions.
task – The task to execute.
-
void cancel(const std::string &name)
Cancels a scheduled repeating task.
- Parameters:
name – The unique name of the task to cancel.
-
~Scheduler()
Destructor ensures all repeating tasks are cleaned up.
Private Members
-
std::unique_ptr<PersistentWorker> persistent_worker_
Worker for managing repeating tasks.
-
void schedule_once(int64_t delay_ms, const std::function<void()> &task)