setTimer

Returns a new armed timer.

Note that timers can only work if an event loop is running, explicitly or implicitly by running a blocking operation, such as sleep or File.read.

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

Parameters

timeout Duration

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

callback Timer.Callback

If non-null, 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 nothrow {
	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, toDelegate(&printTime), true);
}

See Also

createTimer

Meta