Class: RestCore::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/rest-core/timer.rb

Constant Summary collapse

TimerGen =
Timers.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout, error, &block) ⇒ Timer

Returns a new instance of Timer.



8
9
10
11
12
13
# File 'lib/rest-core/timer.rb', line 8

def initialize timeout, error, &block
  self.timeout = timeout
  self.error   = error
  self.block   = block
  start
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



7
8
9
# File 'lib/rest-core/timer.rb', line 7

def error
  @error
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/rest-core/timer.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#cancelObject



19
20
21
# File 'lib/rest-core/timer.rb', line 19

def cancel
  timer.cancel
end

#on_timeout(&block) ⇒ Object



15
16
17
# File 'lib/rest-core/timer.rb', line 15

def on_timeout &block
  self.block = block
end

#startObject



23
24
25
26
# File 'lib/rest-core/timer.rb', line 23

def start
  return if timeout.nil? || timeout.zero?
  self.timer = TimerGen.after(timeout){ block.call }
end