Module: Autostager::Timeout

Defined in:
lib/autostager/timeout.rb

Overview

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

Class Method Summary collapse

Class Method Details

.timeout(seconds, err, &block) ⇒ nil

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. rubocop:disable Performance/RedundantBlockCall

Parameters:

  • seconds (Fixnum)

    Expiration time.

  • err (StandardErr)

    Raise err on expiration.

  • block (Block)

    Code that is subject to expiration.

Returns:

  • (nil)

See Also:



18
19
20
21
22
23
24
25
26
# 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