Class: CLI::UI::Spinner::Async

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/ui/spinner/async.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Async

Initializes a new asynchronous spinner with no specific end. Must call .stop to end the spinner

Attributes

  • title - Title of the spinner to use

Example Usage:

CLI::UI::Spinner::Async.new('Title')


22
23
24
25
26
27
28
29
# File 'lib/cli/ui/spinner/async.rb', line 22

def initialize(title)
  require 'thread'
  sg = CLI::UI::Spinner::SpinGroup.new
  @m = Mutex.new
  @cv = ConditionVariable.new
  sg.add(title) { @m.synchronize { @cv.wait(@m) } }
  @t = Thread.new { sg.wait }
end

Class Method Details

.start(title) ⇒ Object

Convenience method for initialize



7
8
9
# File 'lib/cli/ui/spinner/async.rb', line 7

def self.start(title)
  new(title)
end

Instance Method Details

#stopObject

Stops an asynchronous spinner



33
34
35
36
# File 'lib/cli/ui/spinner/async.rb', line 33

def stop
  @m.synchronize { @cv.signal }
  @t.value
end