Exception: Timeout::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/timeout.rb

Overview

Raised by Timeout.timeout when the block times out.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



30
31
32
# File 'lib/timeout.rb', line 30

def thread
  @thread
end

Class Method Details

.catch(*args) ⇒ Object



32
33
34
35
36
37
# File 'lib/timeout.rb', line 32

def self.catch(*args)
  exc = new(*args)
  exc.instance_variable_set(:@thread, Thread.current)
  exc.instance_variable_set(:@catch_value, exc)
  ::Kernel.catch(exc) {yield exc}
end

Instance Method Details

#exceptionObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/timeout.rb', line 39

def exception(*)
  # TODO: use Fiber.current to see if self can be thrown
  if self.thread == Thread.current
    bt = caller
    begin
      throw(@catch_value, bt)
    rescue UncaughtThrowError
    end
  end
  super
end