module Autostager::Timeout

Meta-module to call the correct library method for the version of Ruby on which the autostager runs.

Public Instance Methods

timeout(seconds, err, &block) click to toggle source

The ruby timeout.rb library is unreliable on 1.8.7, so we use a gem to provide timeouts if this script is running on 1.8.7. @see ph7spot.com/musings/system-timer

@param seconds [Fixnum] Expiration time. @param err [StandardErr] Raise err on expiration. @param block [Block] Code that is subject to expiration.

@return [nil] rubocop:disable Performance/RedundantBlockCall

# File lib/autostager/timeout.rb, line 18
def timeout(seconds, err, &block)
  if RUBY_VERSION =~ /1.8/
    require 'system_timer'
    SystemTimer.timeout_after(seconds, err) { block.call }
  else
    require 'timeout'
    ::Timeout.timeout(seconds, err) { block.call }
  end
end