From: Douglas Seifert Date: 2009-09-04T10:55:25+09:00 Subject: Re: Threads - running something in background 7stud's original Updater class seems to meet the requirements.  Are you trying to write a class that will perform some work and then sleep 1.0 seconds and keep a count of the number of iterations it performed? Or are you trying to right a class that will perform some work exactly once per second?  In the first case, your work will not generally fire once a second because the work itself will take a non zero amount of time.  The second case is trickier ... maybe this would work: class PeriodicWorker   def initialize(period = 1.0)     @period = period   end   def run     start = Time.now.to_f     while true       yield       sleep_time = (start + @period) - Time.now.to_f       sleep(sleep_time) rescue nil # Punt if the worker took longer than @period seconds to run       start += @period     end   end end worker = PeriodicWorker.new worker.run do  puts "Time: #{Time.now.to_f}"  sleep 0.22  puts "Finished my work: #{Time.now.to_f}" end The only issue with this class is if the work takes longer than the period, you are creating a spinloop that will suck up 100% of your CPU. -Doug Seifert