Re: Is this a good way of setting up a timer?

2011-06-07 Thread Jonathan M Davis
On 2011-06-03 15:02, Jonathan M Davis wrote: > Incidentally, this use case shows that I should probably add overloads for > some of the basic math functions for Duration... I'm an idiot. I was thinking that min and max were in std.math and specific to built-in types, but we were smarter than that

Re: Is this a good way of setting up a timer?

2011-06-06 Thread Andrej Mitrovic
On 6/6/11, Steven Schveighoffer wrote: > Then, you have a function that sets the bool and signals the condition: > > void endProgram() > { > synchronized(mutex) > { >if(engineActive) >{ >engineActive = false; >cond.notifyAll(); >} > } > }

Re: Is this a good way of setting up a timer?

2011-06-06 Thread Steven Schveighoffer
On Fri, 03 Jun 2011 17:37:40 -0400, Andrej Mitrovic wrote: On 6/3/11, Jonathan M Davis wrote: Generally, you'd just put it to sleep for the period of time that you want to wait for. The only reason that I see to keep waking it up is if it could be interrupted and effectively told to

Re: Is this a good way of setting up a timer?

2011-06-04 Thread Jonathan M Davis
On 2011-06-04 11:14, Andrej Mitrovic wrote: > Hey, so is there a reason I'm not allowed to use immutable here: > > immutable finalTime = Clock.currTime + dur!"seconds"(5); > > Error: cannot implicitly convert expression > (currTime(cast(immutable(TimeZone))opCall()).opBinary(dur(5L))) of > type S

Re: Is this a good way of setting up a timer?

2011-06-04 Thread Andrej Mitrovic
Hey, so is there a reason I'm not allowed to use immutable here: immutable finalTime = Clock.currTime + dur!"seconds"(5); Error: cannot implicitly convert expression (currTime(cast(immutable(TimeZone))opCall()).opBinary(dur(5L))) of type SysTime to immutable(SysTime)

Re: Is this a good way of setting up a timer?

2011-06-03 Thread Andrej Mitrovic
I didn't even think about issue #1. Thanks again!

Re: Is this a good way of setting up a timer?

2011-06-03 Thread Jonathan M Davis
On 2011-06-03 14:37, Andrej Mitrovic wrote: > On 6/3/11, Jonathan M Davis wrote: > > Generally, you'd just put it to sleep for the period of time that you > > want to > > wait for. The only reason that I see to keep waking it up is if it could > > be interrupted and effectively told to wake up - i

Re: Is this a good way of setting up a timer?

2011-06-03 Thread Andrej Mitrovic
On 6/3/11, Jonathan M Davis wrote: > > Generally, you'd just put it to sleep for the period of time that you want > to > wait for. The only reason that I see to keep waking it up is if it could be > interrupted and effectively told to wake up - in which case you would be > sleeping and waking up o

Re: Is this a good way of setting up a timer?

2011-06-03 Thread Jonathan M Davis
On 2011-06-03 14:22, Andrej Mitrovic wrote: > 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 +

Is this a good way of setting up a timer?

2011-06-03 Thread Andrej Mitrovic
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) { Thre