EntropyEngine::Core::Timer
EntropyEngine::Core::Timer
Section titled “EntropyEngine::Core::Timer”A scheduled task that executes after a delay, optionally repeating. More…
#include <Timer.h>
Public Types
Section titled “Public Types”| Name | |
|---|---|
| using std::function< void()> | WorkFunction |
| using std::chrono::steady_clock::time_point | TimePoint |
| using std::chrono::steady_clock::duration | Duration |
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~Timer() Destroys the timer and cancels it if still valid. | |
| Timer & | operator=(Timer && other) Move assignment - transfers ownership. |
| Timer & | operator=(const Timer & ) =delete |
| bool | isValid() const Checks if the timer is still active. |
| bool | isRepeating() const Checks if this is a repeating timer. |
| void | invalidate() Cancels the timer and prevents future executions. |
| Duration | getInterval() const Gets the interval for repeating timers. |
| Timer() =default Creates an invalid timer (no-op). | |
| Timer(Timer && other) Move constructor - transfers ownership. | |
| Timer(const Timer & ) =delete |
Friends
Section titled “Friends”| Name | |
|---|---|
| class | TimerService |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Core::Timer;A scheduled task that executes after a delay, optionally repeating.
Timer provides an NSTimer-style interface for scheduling work with delays. Timers can be one-shot (fire once) or repeating (fire at intervals). All timing is handled automatically by the TimerService using yieldable WorkGraph nodes.
Key features:
- One-shot and repeating timers
- Thread-safe cancellation
- Main thread or background execution
- RAII-safe: timers invalidate on destruction
- No manual memory management
Perfect for:
- Delayed UI updates
- Periodic polling
- Timeout handling
- Animation frames
- Network retry logic
// One-shot timer (fires once after delay)auto timer = timerService.scheduleTimer( std::chrono::milliseconds(500), []{ LOG_INFO("Timer fired!"); }, false // One-shot);
// Repeating timer (fires every interval)auto repeating = timerService.scheduleTimer( std::chrono::seconds(1), []{ updateStats(); }, true // Repeating);
// Cancel timer earlyrepeating.invalidate();
// Main thread timer for UI updatesauto uiTimer = timerService.scheduleTimer( std::chrono::milliseconds(16), // ~60 FPS []{ updateUI(); }, true, // Repeating ExecutionType::MainThread);Public Types Documentation
Section titled “Public Types Documentation”using WorkFunction
Section titled “using WorkFunction”using EntropyEngine::Core::Timer::WorkFunction = std::function<void()>;using TimePoint
Section titled “using TimePoint”using EntropyEngine::Core::Timer::TimePoint = std::chrono::steady_clock::time_point;using Duration
Section titled “using Duration”using EntropyEngine::Core::Timer::Duration = std::chrono::steady_clock::duration;Public Functions Documentation
Section titled “Public Functions Documentation”function ~Timer
Section titled “function ~Timer”~Timer()Destroys the timer and cancels it if still valid.
RAII cleanup - ensures timers are cancelled when they go out of scope. Safe to destroy after manual invalidation.
function operator=
Section titled “function operator=”Timer & operator=( Timer && other)Move assignment - transfers ownership.
Invalidates the current timer before taking ownership of the other. The moved-from timer becomes invalid.
function operator=
Section titled “function operator=”Timer & operator=( const Timer &) =deletefunction isValid
Section titled “function isValid”bool isValid() constChecks if the timer is still active.
Return: true if the timer is valid and hasn’t been cancelled
if (timer.isValid()) { LOG_INFO("Timer still pending");} else { LOG_INFO("Timer fired or was cancelled");}function isRepeating
Section titled “function isRepeating”inline bool isRepeating() constChecks if this is a repeating timer.
Return: true if the timer repeats, false for one-shot
function invalidate
Section titled “function invalidate”void invalidate()Cancels the timer and prevents future executions.
Thread-safe. Safe to call multiple times. After invalidation, the timer will not fire again. For one-shot timers, this prevents the single execution. For repeating timers, this stops all future repetitions.
auto timer = service.scheduleTimer( std::chrono::seconds(5), []{ doWork(); });
// Changed our mindtimer.invalidate(); // Work will never executefunction getInterval
Section titled “function getInterval”inline Duration getInterval() constGets the interval for repeating timers.
Return: The interval duration, or zero for one-shot timers
function Timer
Section titled “function Timer”Timer() =defaultCreates an invalid timer (no-op).
Default-constructed timers do nothing and are already invalidated. Use TimerService::scheduleTimer() to create active timers.
function Timer
Section titled “function Timer”Timer( Timer && other)Move constructor - transfers ownership.
The moved-from timer becomes invalid. Only one Timer can own a scheduled task at a time.
function Timer
Section titled “function Timer”Timer( const Timer &) =deleteFriends
Section titled “Friends”friend TimerService
Section titled “friend TimerService”friend class TimerService( TimerService);Updated on 2026-01-26 at 17:14:35 -0500