Timer Manual

About

A timer can be used to execute a certain function periodically.

TimerInterface

A new timer instance is created with these static functions:

The created timer instance is controlled with these functions:

These observables are called on certain events:

  • ObservableTimerStarted: Notifies the observers that the timer has started.
  • ObservableTimerFinished: Notifies the observers that the timer has finished.
  • ObservableTimerOverload: Notifies the observers that the timer job took longer than the specified interval.
// This example creates a new timer that is executed every second.
// After ten executions, the timer stops itself.
// g_timer is just a maxon::TimerRef instance.
auto TimerFunction = []()
{
DiagnosticOutput("Timer Tick...");
if (g_count < 10)
{
++g_count;
}
else
{
// timer should end
g_timer.Cancel();
}
};
Timer value in seconds.
Definition: timevalue.h:411
static MAXON_FUNCTION Result< TimerRef > AddPeriodicTimer(TimeValue interval, FN &&job, JobQueueInterface *queue)
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
static const JobQueueInterface::Current JOBQUEUE_CURRENT
Equivalent to calling GetDestinationQueue(), you just save a function call.
Definition: jobqueue.h:377
#define iferr_return
Definition: resultbase.h:1465

Further Reading