Module: Garcon::Timeout
Overview
Class methods that are added when you include Garcon::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.
48 49 50 51 52 53 |
# File 'lib/garcon/utility/timeout.rb', line 48 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 |