Class: Restify::Timeout

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

Defined Under Namespace

Classes: Error

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout, target = nil) ⇒ Timeout

Returns a new instance of Timeout.



14
15
16
17
18
19
20
# File 'lib/restify/timeout.rb', line 14

def initialize(timeout, target = nil)
  @timeout = parse_timeout(timeout)
  @target = target

  @interval = ::Hitimes::Interval.new
  @interval.start
end

Class Attribute Details

.default_timeoutObject

Returns the value of attribute default_timeout.



8
9
10
# File 'lib/restify/timeout.rb', line 8

def default_timeout
  @default_timeout
end

Class Method Details

.new(timeout, *args) ⇒ Object



62
63
64
65
66
# File 'lib/restify/timeout.rb', line 62

def new(timeout, *args)
  return timeout if timeout.is_a?(self)

  super
end

Instance Method Details

#exceptionObject



34
35
36
# File 'lib/restify/timeout.rb', line 34

def exception
  Error.new(@target)
end

#timeout!Object

Raises:

  • (self)


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

def timeout!
  raise self if wait_interval <= 0
end

#wait_on!(ivar) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/restify/timeout.rb', line 22

def wait_on!(ivar)
  ivar.value!(wait_interval).tap do
    raise self unless ivar.complete?
  end
rescue ::Timeout::Error
  raise self
end