Sha256: b2fbffb28a414924c3b0b2f2bb3104bd7742a1b3908cc71bc8cbe81ed0556a46

Contents?: true

Size: 579 Bytes

Versions: 29

Compression:

Stored size: 579 Bytes

Contents

module SiteHook
  module_function
  def show_wait_spinner(fps = 10)
    chars   = %w[| / - \\]
    delay   = 1.0 / fps
    iter    = 0
    spinner = 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…
      spinner.join # …and wait for it to do so.
    } # Use the block's return value as the method's
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
site_hook-0.8.2 lib/site_hook/spinner.rb
site_hook-0.8.1 lib/site_hook/spinner.rb
site_hook-0.8.0 lib/site_hook/spinner.rb
site_hook-0.7.0 lib/site_hook/spinner.rb
site_hook-0.6.23 lib/site_hook/spinner.rb
site_hook-0.6.22 lib/site_hook/spinner.rb
site_hook-0.6.21 lib/site_hook/spinner.rb
site_hook-0.6.19 lib/site_hook/spinner.rb
site_hook-0.6.18 lib/site_hook/spinner.rb
site_hook-0.6.17 lib/site_hook/spinner.rb
site_hook-0.6.16 lib/site_hook/spinner.rb
site_hook-0.6.15 lib/site_hook/spinner.rb
site_hook-0.6.14 lib/site_hook/spinner.rb
site_hook-0.6.13 lib/site_hook/spinner.rb
site_hook-0.6.12 lib/site_hook/spinner.rb
site_hook-0.6.11 lib/site_hook/spinner.rb
site_hook-0.6.10 lib/site_hook/spinner.rb
site_hook-0.6.9 lib/site_hook/spinner.rb
site_hook-0.6.8 lib/site_hook/spinner.rb
site_hook-0.6.7 lib/site_hook/spinner.rb