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.6.4 lib/site_hook/spinner.rb
site_hook-0.6.3 lib/site_hook/spinner.rb
site_hook-0.6.2 lib/site_hook/spinner.rb
site_hook-0.6.1 lib/site_hook/spinner.rb
site_hook-0.6.0 lib/site_hook/spinner.rb
site_hook-0.5.0 lib/site_hook/spinner.rb
site_hook-0.4.0 lib/site_hook/spinner.rb
site_hook-0.3.0 lib/site_hook/spinner.rb
site_hook-0.2.0 lib/site_hook/spinner.rb