Class: RichEngine::Timer::Every
- Inherits:
-
Object
- Object
- RichEngine::Timer::Every
- Defined in:
- lib/rich_engine/timer/every.rb
Overview
A scheduler that fires at a fixed interval, created via every.
Instance Method Summary collapse
-
#initialize(interval) ⇒ Every
constructor
A new instance of Every.
-
#interval=(interval) ⇒ void
Changes the firing interval and resets the timer.
-
#update(elapsed_time) ⇒ void
Accumulates elapsed time and marks the scheduler ready once the interval is reached.
-
#when_ready { ... } ⇒ void
Runs the block and resets the timer when the interval has elapsed.
Constructor Details
Instance Method Details
#interval=(interval) ⇒ void
This method returns an undefined value.
Changes the firing interval and resets the timer.
42 43 44 45 |
# File 'lib/rich_engine/timer/every.rb', line 42 def interval=(interval) @interval = interval reset! end |
#update(elapsed_time) ⇒ void
This method returns an undefined value.
Accumulates elapsed time and marks the scheduler ready once the interval is reached.
19 20 21 22 23 24 25 |
# File 'lib/rich_engine/timer/every.rb', line 19 def update(elapsed_time) @timer.update(elapsed_time) if @timer.get >= @interval @ready = true end end |
#when_ready { ... } ⇒ void
This method returns an undefined value.
Runs the block and resets the timer when the interval has elapsed.
31 32 33 34 35 36 |
# File 'lib/rich_engine/timer/every.rb', line 31 def when_ready(&block) if @ready block.call reset! end end |