Module: Deployman::Component::Spinningclock
- Defined in:
- lib/deployman/component/spinningclock.rb
Constant Summary collapse
- @@active =
true
Class Method Summary collapse
Class Method Details
.set_active(active = true) ⇒ Object
29 30 31 |
# File 'lib/deployman/component/spinningclock.rb', line 29 def self.set_active(active = true) @@active = active end |
.show_clock(fps = 10) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/deployman/component/spinningclock.rb', line 5 def self.show_clock(fps = 10) if @@active chars = %w[| / - \\] delay = 1.0/fps iter = 0 clock = Thread.new do while iter do # Keep spinning until told otherwise print chars[(iter+=1) % chars.length] sleep delay print "\b" end end yield.tap { # After yielding to the block, save the return value iter = false # Tell the thread to exit, cleaning up after itself… clock.join # …and wait for it to do so. } # Use the block's return value as the method's else # just execute the block yield end end |