Created
June 25, 2014 23:37
-
-
Save tompave/0f8856f9e43c27d5853b to your computer and use it in GitHub Desktop.
Ruby simple timer
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 timer(seconds, &block) | |
Thread.new { | |
t_0 = Time.now | |
sleep seconds | |
elapsed = Time.now - t_0 | |
puts "timer triggered after #{elapsed} seconds (error: #{elapsed - seconds})." | |
yield | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment