Class: RestCore::Timer
- Inherits:
-
Object
- Object
- RestCore::Timer
- Defined in:
- lib/rest-core/timer.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#cancel ⇒ Object
should never raise!.
-
#initialize(timeout, error, &block) ⇒ Timer
constructor
A new instance of Timer.
- #on_timeout(&block) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(timeout, error, &block) ⇒ Timer
Returns a new instance of Timer.
33 34 35 36 37 38 |
# File 'lib/rest-core/timer.rb', line 33 def initialize timeout, error, &block self.timeout = timeout self.error = error self.block = block start end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
32 33 34 |
# File 'lib/rest-core/timer.rb', line 32 def error @error end |
#timeout ⇒ Object
Returns the value of attribute timeout.
32 33 34 |
# File 'lib/rest-core/timer.rb', line 32 def timeout @timeout end |
Instance Method Details
#cancel ⇒ Object
should never raise!
45 46 47 48 |
# File 'lib/rest-core/timer.rb', line 45 def cancel timer.cancel self.block = nil end |
#on_timeout(&block) ⇒ Object
40 41 42 |
# File 'lib/rest-core/timer.rb', line 40 def on_timeout &block self.block = block end |
#start ⇒ Object
50 51 52 53 |
# File 'lib/rest-core/timer.rb', line 50 def start return if timeout.nil? || timeout.zero? self.timer = self.class.group.after(timeout){ block.call if block } end |