Skip to content

Instantly share code, notes, and snippets.

@edwinlab
Created November 3, 2017 04:00
Show Gist options
  • Select an option

  • Save edwinlab/f303d8e1c318d31d644d87250f386fb5 to your computer and use it in GitHub Desktop.

Select an option

Save edwinlab/f303d8e1c318d31d644d87250f386fb5 to your computer and use it in GitHub Desktop.
require 'timeout'
def a_method(iterations)
Timeout::timeout(1) do # 1 second
iterations.times { |i| print("#{i} "); sleep(0.1) }
end
rescue Timeout::Error
print("TIMEOUT")
ensure
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment