Method: CLI::UI::Spinner::SpinGroup#initialize

Defined in:
lib/cli/ui/spinner/spin_group.rb

#initialize(auto_debrief: true, interrupt_debrief: false, max_concurrent: 0, work_queue: nil, to: $stdout) ⇒ SpinGroup

Initializes a new spin group This lets you add Task objects to the group to multi-thread work

Options

  • :auto_debrief - Automatically debrief exceptions or through success_debrief? Default to true

  • :interrupt_debrief - Automatically debrief on interrupt. Default to false

  • :max_concurrent - Maximum number of concurrent tasks. Default is 0 (effectively unlimited)

  • :work_queue - Custom WorkQueue instance. If not provided, a new one will be created

  • :to - Target stream, like $stdout or $stderr. Can be anything with print and puts methods, or under Sorbet, IO or StringIO. Defaults to $stdout

Example Usage

CLI::UI::SpinGroup.new do |spin_group|
  spin_group.add('Title')   { |spinner| sleep 3.0 }
  spin_group.add('Title 2') { |spinner| sleep 3.0; spinner.update_title('New Title'); sleep 3.0 }
end

Output:

: (?auto_debrief: bool, ?interrupt_debrief: bool, ?max_concurrent: Integer, ?work_queue: WorkQueue?, ?to: io_like) -> void



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cli/ui/spinner/spin_group.rb', line 63

def initialize(auto_debrief: true, interrupt_debrief: false, max_concurrent: 0, work_queue: nil, to: $stdout)
  @m = Mutex.new
  @tasks = []
  @puts_above = []
  @auto_debrief = auto_debrief
  @interrupt_debrief = interrupt_debrief
  @start = Time.new
  @stopped = false
  @internal_work_queue = work_queue.nil?
  @work_queue = work_queue || WorkQueue.new(max_concurrent.zero? ? 1024 : max_concurrent) #: WorkQueue
  if block_given?
    yield self
    wait(to: to)
  end
end