setTimer

Returns a new armed timer.

Note that timers can only work if an event loop is running.

Passing a @system callback is scheduled for deprecation. Use a @safe callback instead.

  1. Timer setTimer(Duration timeout, void delegate() @(safe) callback, bool periodic)
    @safe
    setTimer
    (
    Duration timeout
    ,
    void delegate
    ()
    @safe
    callback
    ,
    bool periodic = false
    )
  2. Timer setTimer(Duration timeout, void delegate() @(system) callback, bool periodic)

Parameters

timeout Duration

Determines the minimum amount of time that elapses before the timer fires.

callback void delegate
()
@safe

This delegate will be called when the timer fires

periodic bool

Speficies if the timer fires repeatedly or only once

Return Value

Type: Timer

Returns a Timer object that can be used to identify and modify the timer.

Examples

void printTime()
@safe {
	import std.datetime;
	logInfo("The time is: %s", Clock.currTime());
}

void test()
{
	import vibe.core.core;
	// start a periodic timer that prints the time every second
	setTimer(1.seconds, &printTime, true);
}

See Also

createTimer

Meta