Timer

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

More...

Constructors

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

Create a timer with a callback when it triggers.

Destructor

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

Members

Functions

destroy
void destroy()

Stop and destroy the timer object.

Detailed Description

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

There are currently no one-off timers (instead, just create one and destroy it when it is triggered) nor are there pause/resume functions - the timer must again be destroyed and recreated if you want to pause it.

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.

Suggestion Box / Bug Report