Timer

A timer that will trigger your function on a given interval.

More...

Constructors

this
this(bool actuallyInitialize)

Creates an initialized, but unarmed timer. You must call other methods later.

this
this(int intervalInMilliseconds, void delegate() onPulse, bool repeats)

Create a timer with a callback when it triggers.

this
this(SimplifiedUtcTimestamp when, void delegate() onTimeArrived)

Sets a one-of timer that happens some time after the given timestamp, then destroys itself

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

cancel
void cancel()
changeTime
void changeTime(int intervalInMilliseconds, bool repeats)
destroy
void destroy()

Stop and destroy the timer object.

pause
void pause()
setPulseCallback
void setPulseCallback(void delegate() onPulse)
unpause
void unpause()

Detailed Description

You create a timer with an interval and a callback. It will continue to fire on the interval until it is destroyed.

auto timer = new Timer(50, { it happened!; });
timer.destroy();

Timers can only be expected to fire when the event loop is running and only once per iteration through the event loop.

Meta

History

Prior to December 9, 2020, a timer pulse set too high with a handler too slow could lock up the event loop. It now guarantees other things will get a chance to run between timer calls, even if that means not keeping up with the requested interval.