Class: PromisePool::Timer
- Inherits:
-
Object
- Object
- PromisePool::Timer
- Defined in:
- lib/promise_pool/timer.rb
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#timer ⇒ Object
Returns the value of attribute timer.
Instance Method Summary collapse
-
#cancel ⇒ Object
should never raise!.
-
#initialize(timeout, error = Error.new('execution expired')) ⇒ Timer
constructor
A new instance of Timer.
- #on_timeout(&block) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(timeout, error = Error.new('execution expired')) ⇒ Timer
Returns a new instance of Timer.
36 37 38 39 |
# File 'lib/promise_pool/timer.rb', line 36 def initialize timeout, error=Error.new('execution expired') self.timeout = timeout self.error = error end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
35 36 37 |
# File 'lib/promise_pool/timer.rb', line 35 def error @error end |
#timeout ⇒ Object
Returns the value of attribute timeout.
35 36 37 |
# File 'lib/promise_pool/timer.rb', line 35 def timeout @timeout end |
#timer ⇒ Object
Returns the value of attribute timer.
35 36 37 |
# File 'lib/promise_pool/timer.rb', line 35 def timer @timer end |
Instance Method Details
#cancel ⇒ Object
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 end |
#start ⇒ Object
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 |