From: Tim Hunter Date: 2007-09-29T04:18:32+09:00 Subject: Re: sleep for lesser of two values Earle Clubb wrote: > I have a loop that runs for a variable amount of time, as defined by > @duration. I need to re-execute the command every 15 seconds for the > length of @duration, which is a float and can have any value. Can > anyone think of a more elegant way to do this than the code below? > > end_time = Time.now + @duration > while (t = Time.now) < end_time > # execute command > sleep((15 < (end_time - t)) ? 15 : (end_time - t)) > end > > > Thanks, > Earle sleep([15, end_time -t].min) -- RMagick OS X Installer [http://rubyforge.org/projects/rmagick/] RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618] RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]