From: Eric Hodel Date: 2009-05-31T00:21:59+09:00 Subject: Re: Runnin code at a certain time? On May 29, 2009, at 12:49, Caleb Clausen wrote: > On 5/28/09, Eric Hodel wrote: >> On May 25, 2009, at 13:36, Caleb Clausen wrote: >>> Do you want your whole program to stop until some target time? In >>> that >>> case, something as simple as >>> >>> sleep(target_time-Time.now) >>> code_to_be_delayed >>> >>> will do the trick nicely. >> >> Note that #sleep won't necessarily sleep as long as you like (second >> sentence): >> >> $ ri Kernel#sleep >> ----------------------------------------------------------- >> Kernel#sleep >> sleep([duration]) => fixnum >> >> From Ruby 1.8 >> ------------------------------------------------------------------------ >> Suspends the current thread for duration seconds (which may be >> any >> number, including a Float with fractional seconds). Returns the >> actual number of seconds slept (rounded), which may be less than >> that asked for if another thread calls Thread#run. Zero >> arguments >> causes sleep to sleep forever. >> [...] > > Is there some particular danger that Thread#run will be called on my > threads without my asking? If it's library code, yes. If it's application code, probably not.