Class: RestCore::Timer
- Inherits:
-
Object
- Object
- RestCore::Timer
- Defined in:
- lib/rest-core/timer.rb
Constant Summary collapse
- TimerGen =
if Timers.respond_to?(:new) Timers.new else Timers::Group.new end
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.
12 13 14 15 16 17 |
# File 'lib/rest-core/timer.rb', line 12 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.
11 12 13 |
# File 'lib/rest-core/timer.rb', line 11 def error @error end |
#timeout ⇒ Object
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/rest-core/timer.rb', line 11 def timeout @timeout end |
Instance Method Details
#cancel ⇒ Object
23 24 25 |
# File 'lib/rest-core/timer.rb', line 23 def cancel timer.cancel end |
#on_timeout(&block) ⇒ Object
19 20 21 |
# File 'lib/rest-core/timer.rb', line 19 def on_timeout &block self.block = block end |
#start ⇒ Object
27 28 29 30 |
# File 'lib/rest-core/timer.rb', line 27 def start return if timeout.nil? || timeout.zero? self.timer = TimerGen.after(timeout){ block.call } end |