Class: Instrumental::Intervalometer
- Inherits:
-
Object
- Object
- Instrumental::Intervalometer
- Defined in:
- lib/instrumental/intervalometer.rb
Instance Method Summary collapse
- #halt ⇒ Object
-
#initialize(period = 60.0) ⇒ Intervalometer
constructor
A new instance of Intervalometer.
-
#run ⇒ Object
Runs a passed block at intervals defined by the period set during initialization.
Constructor Details
#initialize(period = 60.0) ⇒ Intervalometer
Returns a new instance of Intervalometer.
4 5 6 7 8 |
# File 'lib/instrumental/intervalometer.rb', line 4 def initialize(period=60.0) @period = period.to_f @running = true @run_next = Time.now end |
Instance Method Details
#halt ⇒ Object
10 11 12 13 14 |
# File 'lib/instrumental/intervalometer.rb', line 10 def halt # TODO: See if it would be possible for the intervalometer to do a # final run before the thread exits. @running = false end |
#run ⇒ Object
Runs a passed block at intervals defined by the period set during initialization. Uses intervalometer to keep reasonably precise intervals.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/instrumental/intervalometer.rb', line 18 def run while @running if Time.now < @run_next sleep @run_next - Time.now end @run_next = Time.now + @period yield end end |