Skip to content

Instantly share code, notes, and snippets.

@tompave
Created June 25, 2014 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tompave/0f8856f9e43c27d5853b to your computer and use it in GitHub Desktop.
Save tompave/0f8856f9e43c27d5853b to your computer and use it in GitHub Desktop.
Ruby simple timer
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