EntropyEngine::Core::TimerService
EntropyEngine::Core::TimerService
Section titled “EntropyEngine::Core::TimerService”Service for managing timers with WorkGraph backing. More…
#include <TimerService.h>
Inherits from EntropyEngine::Core::EntropyService, EntropyEngine::Core::EntropyObject
Public Classes
Section titled “Public Classes”| Name | |
|---|---|
| struct | Config Configuration for the timer service. |
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~TimerService() override Destroys the timer service and cancels all active timers. | |
| virtual const char * | version() const override |
| virtual void | unload() override |
| virtual TypeSystem::TypeID | typeId() const override |
| virtual void | stop() override |
| virtual void | start() override |
| void | setWorkService(Concurrency::WorkService * workService) Sets the WorkService reference (must be called before start). |
| Timer | scheduleTimer(std::chrono::steady_clock::duration interval, Timer::WorkFunction work, bool repeating =false, Concurrency::ExecutionType executionType =Concurrency::ExecutionType::AnyThread) Schedules a timer to execute after a delay. |
| size_t | processReadyTimers() Checks for ready timers and schedules them for execution. |
| virtual const char * | name() const override |
| virtual void | load() override |
| virtual const char * | id() const override |
| size_t | getActiveTimerCount() const Gets the number of currently active timers. |
| virtual std::vector< TypeSystem::TypeID > | dependsOnTypes() const override |
| virtual std::vector< std::string > | dependsOn() const override |
| TimerService() Creates a timer service with default configuration. | |
| TimerService(const Config & config) Creates a timer service with custom configuration. |
Friends
Section titled “Friends”| Name | |
|---|---|
| class | Timer |
Additional inherited members
Section titled “Additional inherited members”Public Functions inherited from EntropyEngine::Core::EntropyService
| Name | |
|---|---|
| ~EntropyService() override =default | |
| ServiceState | state() const |
| virtual const char * | className() const override Runtime class name for diagnostics and reflection. |
Protected Functions inherited from EntropyEngine::Core::EntropyService
| Name | |
|---|---|
| void | setState(ServiceState s) |
Friends inherited from EntropyEngine::Core::EntropyService
| Name | |
|---|---|
| class | EntropyServiceRegistry |
Protected Classes inherited from EntropyEngine::Core::EntropyObject
| Name | |
|---|---|
| struct | HandleCore Optional handle identity stamped by an owner/registry. |
Public Functions inherited from EntropyEngine::Core::EntropyObject
| Name | |
|---|---|
| virtual | ~EntropyObject() =default |
| virtual const TypeSystem::TypeInfo * | typeInfo() const Optional richer type information; may be null. |
| bool | tryRetain() const Attempts to retain only if the object is still alive. |
| virtual std::string | toString() const Human-readable short string (class@ptr by default). |
| void | retain() const Increments the reference count. |
| void | release() const Decrements the reference count and deletes when it reaches zero. |
| uint32_t | refCount() const Current reference count (approximate under contention). |
| EntropyObject & | operator=(const EntropyObject & ) =delete |
| EntropyObject & | operator=(EntropyObject && ) =delete |
| bool | hasHandle() const |
| template <class OwnerT > OwnerT * | handleOwnerAs() const Returns the stamped owner pointer cast to the requested type. |
| const void * | handleOwner() const |
| uint32_t | handleIndex() const |
| uint64_t | handleId() const |
| uint32_t | handleGeneration() const |
| WeakControlBlock * | getWeakControlBlock() const Lazily retrieves or creates the weak control block. |
| virtual std::string | description() const Long-form description; defaults to toString(). |
| virtual std::string | debugString() const Debug-oriented string including refcount and handle when present. |
| virtual const char * | className() const Runtime class name for diagnostics and reflection. |
| virtual uint64_t | classHash() const Stable type hash for cross-language identification. |
| EntropyObject() =default | |
| EntropyObject(EntropyObject && ) =delete | |
| EntropyObject(const EntropyObject & ) =delete |
Protected Functions inherited from EntropyEngine::Core::EntropyObject
| Name | |
|---|---|
| void | _setHandleIdentity(void * owner, uint32_t index, uint32_t generation) |
| void | _clearHandleIdentity() |
Protected Attributes inherited from EntropyEngine::Core::EntropyObject
| Name | |
|---|---|
| std::atomic< WeakControlBlock * > | _weakBlock Lazily allocated control block for weak refs. |
| std::atomic< uint32_t > | _refCount Thread-safe retain/release counter. |
| struct EntropyEngine::Core::EntropyObject::HandleCore | _handle |
Friends inherited from EntropyEngine::Core::EntropyObject
| Name | |
|---|---|
| struct | HandleAccess |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Core::TimerService;Service for managing timers with WorkGraph backing.
TimerService provides NSTimer-style delayed execution integrated with the EntropyEngine service architecture. All timers are backed by yieldable WorkGraph nodes, allowing efficient scheduling without dedicated timer threads.
Key features:
- One-shot and repeating timers
- Main thread or background execution
- Automatic integration with WorkService
- No polling overhead - uses yieldable nodes
- RAII-safe timer management
Integration:
- Registered with ServiceRegistry during application startup
- Depends on WorkService for execution
- Main thread timers execute via WorkService::executeMainThreadWork()
- Background timers execute on worker threads
Perfect for:
- Delayed UI updates
- Periodic polling
- Timeout handling
- Animation timing
- Retry logic
// In EntropyApplication setupauto timerService = std::make_shared<TimerService>();services.registerService<TimerService>(timerService);
// Later, from any systemauto& timers = app.getServices().get<TimerService>();
// One-shot timerauto timer = timers->scheduleTimer( std::chrono::seconds(5), []{ LOG_INFO("5 seconds elapsed"); });
// Repeating timer on main threadauto frameTimer = timers->scheduleTimer( std::chrono::milliseconds(16), []{ updateFrame(); }, true, // Repeating ExecutionType::MainThread);
// Cancel timer earlyframeTimer.invalidate();Public Functions Documentation
Section titled “Public Functions Documentation”function ~TimerService
Section titled “function ~TimerService”~TimerService() overrideDestroys the timer service and cancels all active timers.
function version
Section titled “function version”inline virtual const char * version() const overrideReimplements: EntropyEngine::Core::EntropyService::version
function unload
Section titled “function unload”virtual void unload() overrideReimplements: EntropyEngine::Core::EntropyService::unload
function typeId
Section titled “function typeId”inline virtual TypeSystem::TypeID typeId() const overrideReimplements: EntropyEngine::Core::EntropyService::typeId
function stop
Section titled “function stop”virtual void stop() overrideReimplements: EntropyEngine::Core::EntropyService::stop
function start
Section titled “function start”virtual void start() overrideReimplements: EntropyEngine::Core::EntropyService::start
function setWorkService
Section titled “function setWorkService”void setWorkService( Concurrency::WorkService * workService)Sets the WorkService reference (must be called before start).
Parameters:
- workService The WorkService to use for timer execution
Exceptions:
- std::runtime_error if WorkContractGroup registration fails
This method allows the application to inject the WorkService dependency after both services have been created. Must be called after load() and before start().
function scheduleTimer
Section titled “function scheduleTimer”Timer scheduleTimer( std::chrono::steady_clock::duration interval, Timer::WorkFunction work, bool repeating =false, Concurrency::ExecutionType executionType =Concurrency::ExecutionType::AnyThread)Schedules a timer to execute after a delay.
Parameters:
- interval Time to wait before first execution
- work Function to execute when timer fires
- repeating If true, timer repeats; if false, fires once
- executionType Where to execute: MainThread or AnyThread
Return: Timer handle for cancellation and status checking
Creates a new timer that executes the provided work function after the specified interval. For repeating timers, the work executes repeatedly at the interval until cancelled.
Thread-safe. Can be called from any thread. The work function will execute on the specified execution context (main thread or worker threads).
// One-shot timeoutauto timeout = service.scheduleTimer( std::chrono::seconds(30), []{ handleTimeout(); }, false // One-shot);
// Repeating poll every 100msauto poll = service.scheduleTimer( std::chrono::milliseconds(100), []{ checkStatus(); }, true // Repeating);
// Main thread UI update at 60 FPSauto frameUpdate = service.scheduleTimer( std::chrono::milliseconds(16), []{ renderFrame(); }, true, // Repeating ExecutionType::MainThread);function processReadyTimers
Section titled “function processReadyTimers”size_t processReadyTimers()Checks for ready timers and schedules them for execution.
Return: Number of timers that were woken up and scheduled
Examines timers that are waiting for their scheduled time and wakes up any whose time has arrived. Call this periodically from your main loop to ensure timers fire promptly, especially when the system is idle.
// In main loopwhile (running) { timerService->processReadyTimers(); // ... other work ... std::this_thread::sleep_for(10ms);}function name
Section titled “function name”inline virtual const char * name() const overrideReimplements: EntropyEngine::Core::EntropyService::name
function load
Section titled “function load”virtual void load() overrideReimplements: EntropyEngine::Core::EntropyService::load
function id
Section titled “function id”inline virtual const char * id() const overrideReimplements: EntropyEngine::Core::EntropyService::id
function getActiveTimerCount
Section titled “function getActiveTimerCount”size_t getActiveTimerCount() constGets the number of currently active timers.
Return: Count of timers that haven’t been cancelled or completed
function dependsOnTypes
Section titled “function dependsOnTypes”virtual std::vector< TypeSystem::TypeID > dependsOnTypes() const overrideReimplements: EntropyEngine::Core::EntropyService::dependsOnTypes
function dependsOn
Section titled “function dependsOn”inline virtual std::vector< std::string > dependsOn() const overrideReimplements: EntropyEngine::Core::EntropyService::dependsOn
function TimerService
Section titled “function TimerService”TimerService()Creates a timer service with default configuration.
function TimerService
Section titled “function TimerService”explicit TimerService( const Config & config)Creates a timer service with custom configuration.
Parameters:
- config Service configuration
Friends
Section titled “Friends”friend Timer
Section titled “friend Timer”friend class Timer( Timer);Updated on 2026-01-26 at 16:50:32 -0500