Module: Elastic::Beanstalk::Spinner
Instance Method Summary collapse
Instance Method Details
#show(fps = 10) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/elastic/beanstalk/spinner.rb', line 8 def show(fps=10) chars = %w{ | / - \\ } delay = 1.0/fps iter = 0 spinner = Thread.new do while iter do # Keep spinning until told otherwise print chars[0] sleep delay print "\b" chars.push chars.shift end end yield.tap {# After yielding to the block, save the return value iter = false # Tell the thread to exit, cleaning up after itself… spinner.join # …and wait for it to do so. } # Use the block's return value as the method's end |