Class: RestCore::Timer
- Inherits:
-
Object
- Object
- RestCore::Timer
- Defined in:
- lib/rest-core/timer.rb
Constant Summary collapse
- TimerGen =
Timers.new
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
-
#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.
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
#error ⇒ Object
Returns the value of attribute error.
7 8 9 |
# File 'lib/rest-core/timer.rb', line 7 def error @error end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/rest-core/timer.rb', line 7 def timeout @timeout end |
Instance Method Details
#cancel ⇒ Object
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 |
#start ⇒ Object
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 |