Class: Zold::Metronome
- Inherits:
-
Object
- Object
- Zold::Metronome
- Defined in:
- lib/zold/metronome.rb
Overview
Metronome
Instance Method Summary collapse
- #add(routine) ⇒ Object
-
#initialize(log = Log::Quiet.new) ⇒ Metronome
constructor
A new instance of Metronome.
- #stop ⇒ Object
Constructor Details
Instance Method Details
#add(routine) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zold/metronome.rb', line 36 def add(routine) @threads << Thread.start do VerboseThread.new(@log).run(true) do Thread.current.name = routine.class.name step = 0 loop do start = Time.now routine.exec(step) sleep(1) step += 1 @log.debug("Routine #{routine.class.name} ##{step} done in #{((Time.now - start) / 60).round(2)}s)") end end end @log.info("Added #{routine.class.name} to the metronome") end |
#stop ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/zold/metronome.rb', line 53 def stop @threads.each do |t| t.exit @log.debug("#{t.name} thread stopped") end @log.info("#{@threads.count} routine threads stopped") end |