Module: Dump::ContiniousTimeout

Defined in:
lib/dump/continious_timeout.rb

Overview

Timeout if does not finish or defer in requested time

Defined Under Namespace

Classes: Deferer, RestartException, TimeoutException

Class Method Summary collapse

Class Method Details

.timeout(sec) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dump/continious_timeout.rb', line 21

def self.timeout(sec)
  x = Thread.current
  y = Thread.start do
    1.times do
      begin
        sleep sec
      rescue RestartException
        retry
      end
    end
    x.raise TimeoutException, 'execution expired' if x.alive?
  end
  yield Deferer.new(y)
ensure
  y.kill if y && y.alive?
end