class Pantry::Command::TrackResponses

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.

Public Class Methods

new() click to toggle source
# File lib/pantry/command.rb, line 162
def initialize
  @expected_clients      = []
  @received_from_clients = []
end

Public Instance Methods

all_response_received?() click to toggle source
# File lib/pantry/command.rb, line 187
def all_response_received?
  !@expected_clients.empty? && @expected_clients.length == @received_from_clients.length
end
from_client?() click to toggle source
# File lib/pantry/command.rb, line 183
def from_client?
  !@latest_response.from_server?
end
from_server?() click to toggle source
# File lib/pantry/command.rb, line 179
def from_server?
  @latest_response.from_server? && !@latest_response[:client_response_list]
end
new_response(response) click to toggle source
# 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