Is this a good way of setting up a timer?

Andrej Mitrovic none at none.none
Fri Jun 3 14:22:46 PDT 2011


I can't find any timers in phobos, basically I want some loop to run for a predetermined amount of time. Currently I use this:

import core.time;
import std.datetime;
import core.thread;

void main()
{
    auto finalTime = Clock.currTime + dur!"seconds"(4);
    
    while (true)
    {
        Thread.sleep(dur!("seconds")(1));
        if (Clock.currTime > finalTime)
            break;   
    }
}

Is that check doing any conversions in the background, or am I safe (performance-wise)? Well I'm probably wasting performance on waking up the thread every second.. hmm.


More information about the Digitalmars-d-learn mailing list