Module: Hoodie::Timeout
Overview
Class methods that are added when you include Hoodie::Timeout
Instance Method Summary collapse
-
#timeout(seconds) ⇒ Object
Wait the given number of seconds for the block operation to complete.
Instance Method Details
#timeout(seconds) ⇒ Object
Wait the given number of seconds for the block operation to complete. Intended to be a simpler and more reliable replacement to the Ruby standard library ‘Timeout::timeout` method.
47 48 49 50 51 52 |
# File 'lib/hoodie/utils/timeout.rb', line 47 def timeout(seconds) thread = Thread.new { Thread.current[:result] = yield } thread.join(seconds) ? (return thread[:result]) : (raise TimeoutError) ensure Thread.kill(thread) unless thread.nil? end |