Skip to content

Instantly share code, notes, and snippets.

@Bregor
Created May 18, 2009 13:07
Show Gist options
  • Save Bregor/113460 to your computer and use it in GitHub Desktop.
Save Bregor/113460 to your computer and use it in GitHub Desktop.
def time_block(&block)
raise "No block given" unless block_given?
start_time = Time.now
Thread.new { yield }
Time.now - start_time
end
def repeat_every(seconds, &block)
raise "No block given" unless block_given?
begin
time_spent = time_block { yield }
sleep(seconds - time_spent)
end while time_spent < seconds
end
repeat_every(300) do
puts "Start checking: #{Time.now}"
puts "End checking: #{Time.now}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment