Created
May 18, 2009 13:07
-
-
Save Bregor/113460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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