From c1615f86f03074498984853327f9966b48328073 Mon Sep 17 00:00:00 2001 From: Dave Copeland Date: Thu, 19 May 2011 20:56:35 -0400 Subject: [PATCH 1/3] asdf --- lib/timeout.rb | 41 +++++++++++++++++++++++------------------ 1 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/timeout.rb b/lib/timeout.rb index f9d52ab..88dfb72 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -1,23 +1,24 @@ # = timeout.rb # -# execution timeout +# Timeout long-running # -# = Synopsis +# == Synopsis # # require 'timeout' # status = Timeout::timeout(5) { -# # Something that should be interrupted if it takes too much time... +# # Something that should be interrupted if it takes more than 5 seconds... # } # -# = Description +# == Description # -# A way of performing a potentially long-running operation in a thread, and terminating -# it's execution if it hasn't finished by a fixed amount of time. +# Timeout provides a way to auto-terminate a potentially long-running +# operation if it hasn't finished in a fixed amount of time. # -# Previous versions of timeout didn't provide use a module for namespace. This version -# provides both Timeout.timeout, and a backwards-compatible #timeout. +# Previous versions didn't use a module for namespacing, however +# #timeout is provided for backwards compatibility. You +# should prefer Timeout#timeout instead. # -# = Copyright +# == Copyright # # Copyright:: (C) 2000 Network Applied Communication Laboratory, Inc. # Copyright:: (C) 2000 Information-technology Promotion Agency, Japan @@ -34,14 +35,18 @@ module Timeout CALLER_OFFSET = ((c = caller[0]) && THIS_FILE =~ c) ? 1 : 0 # :startdoc: - # Executes the method's block. If the block execution terminates before - # +sec+ seconds has passed, it returns the result value of the block. - # If not, it terminates the execution and raises +exception+ (which defaults - # to Timeout::Error). + # Perform an operation in a block, timing it out if it takes longer + # than +sec+ seconds to complete. # - # Note that this is both a method of module Timeout, so you can 'include Timeout' - # into your classes so they have a #timeout method, as well as a module method, - # so you can call it directly as Timeout.timeout(). + # +sec+:: number of seconds to wait for the block to terminate + # +klass+:: Exception Class to raise if the block fails to terminate + # in +sec+ seconds. Omitting will use the default, Timeout::Error + # + # The block will be executed on another thread and + # will be given one argument: +sec+. + # + # Returns the result of the block *if* the block completed before + # +sec+ seconds, otherwise throws an exception, based on the value of +klass+. def timeout(sec, klass = nil) #:yield: +sec+ return yield(sec) if sec == nil or sec.zero? exception = klass || Class.new(ExitException) @@ -85,8 +90,8 @@ end # # Timeout::timeout(n, e, &block). # -# Defined for backwards compatibility with earlier versions of timeout.rb, see -# Timeout#timeout. +# This method is deprecated and provided only for backwards compatibility. +# You should use Timeout#timeout instead. def timeout(n, e = nil, &block) Timeout::timeout(n, e, &block) end -- 1.7.3.4