Class: PromisePool::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/promise_pool/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Timer.



34
35
36
37
38
39
# File 'lib/promise_pool/timer.rb', line 34

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

Instance Attribute Details

#errorObject

Returns the value of attribute error.



33
34
35
# File 'lib/promise_pool/timer.rb', line 33

def error
  @error
end

#timeoutObject

Returns the value of attribute timeout.



33
34
35
# File 'lib/promise_pool/timer.rb', line 33

def timeout
  @timeout
end

#timerObject

Returns the value of attribute timer.



33
34
35
# File 'lib/promise_pool/timer.rb', line 33

def timer
  @timer
end

Instance Method Details

#cancelObject

should never raise!



47
48
49
50
# File 'lib/promise_pool/timer.rb', line 47

def cancel
  timer.cancel if timer
  self.block = nil
end

#on_timeout(&block) ⇒ Object



41
42
43
44
# File 'lib/promise_pool/timer.rb', line 41

def on_timeout &block
  self.block = block
  start if block_given?
end

#startObject



52
53
54
55
# File 'lib/promise_pool/timer.rb', line 52

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