class Spring::Application

def wait(pid, streams, client)

def wait(pid, streams, client)
  @mutex.synchronize { @waiting << pid }
  # Wait in a separate thread so we can run multiple commands at once
  Thread.new {
    begin
      _, status = Process.wait2 pid
      log "#{pid} exited with #{status.exitstatus}"
      streams.each(&:close)
      client.puts(status.exitstatus)
      client.close
    ensure
      @mutex.synchronize { @waiting.delete pid }
      exit_if_finished
    end
  }
end