Class: Pantry::Command::TrackResponses
- Inherits:
-
Object
- Object
- Pantry::Command::TrackResponses
- Defined in:
- lib/pantry/command.rb
Overview
Internal state tracking of server and client responses. When a Client Command is triggered, the Server first responses with a message containing the list of Clients who will execute the Command and respond. Then we need to keep track of all the Clients who have responded so we know when the command has fully finished across all Clients.
Instance Method Summary collapse
- #all_response_received? ⇒ Boolean
- #from_client? ⇒ Boolean
- #from_server? ⇒ Boolean
-
#initialize ⇒ TrackResponses
constructor
A new instance of TrackResponses.
- #new_response(response) ⇒ Object
Constructor Details
#initialize ⇒ TrackResponses
Returns a new instance of TrackResponses.
162 163 164 165 |
# File 'lib/pantry/command.rb', line 162 def initialize @expected_clients = [] @received_from_clients = [] end |
Instance Method Details
#all_response_received? ⇒ Boolean
187 188 189 |
# File 'lib/pantry/command.rb', line 187 def all_response_received? !@expected_clients.empty? && @expected_clients.length == @received_from_clients.length end |
#from_client? ⇒ Boolean
183 184 185 |
# File 'lib/pantry/command.rb', line 183 def from_client? !@latest_response.from_server? end |
#from_server? ⇒ Boolean
179 180 181 |
# File 'lib/pantry/command.rb', line 179 def from_server? @latest_response.from_server? && !@latest_response[:client_response_list] end |
#new_response(response) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/pantry/command.rb', line 167 def new_response(response) @latest_response = response if response[:client_response_list] @expected_clients = response.body count = @expected_clients.length Pantry.ui.say("Expecting response from #{count} client#{count == 1 ? "" : "s"}...") elsif from_client? @received_from_clients << response end end |