Timer in D.API?

Christopher Wright dhasenan at gmail.com
Wed Mar 4 15:23:58 PST 2009


Steve Schveighoffer wrote:
> e.g.:
> import tango.time.Clock;
> ...
> auto curTime = Clock.now;
> auto period = TimeSpan.fromMilliseconds(300);
> auto nextTime = curTime + period;
> for(int counter=0;;counter++)
> {
>   Stdout(displayString[counter%displayString.length]).flush;
>   auto timeToSleep = nextTime - curTime;
>   if(timeToSleep > TimeSpan.zero)
>     Thread.sleep(timeToSleep.interval);
>   curTime = Clock.now;
>   nextTime += period;
> }

I think the request was for a more event-like mechanism for timers.


More information about the Digitalmars-d-learn mailing list