Class: CLI::Mastermind::UserInterface::AsyncSpinners

Inherits:
UI::SpinGroup
  • Object
show all
Defined in:
lib/cli/mastermind/user_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAsyncSpinners

Returns a new instance of AsyncSpinners.



142
143
144
145
# File 'lib/cli/mastermind/user_interface.rb', line 142

def initialize
  @results = {}
  super
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



140
141
142
# File 'lib/cli/mastermind/user_interface.rb', line 140

def results
  @results
end

Instance Method Details

#await(title) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cli/mastermind/user_interface.rb', line 147

def await(title)
  @results[title] = nil

  add(title) do |spinner|
    catch(:success) do
      msg = catch(:fail) do
        @results[title] = yield spinner
        throw :success
      end

      puts msg
      CLI::UI::Spinner::TASK_FAILED
    end
  end
end