title: How To Know All Asynchronous HTTP Calls are Completed
body: <p>I am trying to figure out how to determine if all async HTTP GET requests I've made have completed, so that I can execute another method. For context, I have something similar to the code below:</p>
  
  <pre><code>public void init() throws IOException {
      Map&lt;String, CustomObject&gt; mapOfObjects = new HashMap&lt;String, CustomObject&gt;();
      ObjectMapper mapper = new ObjectMapper();
  
      // some code to populate the map
  
      mapOfObjects.forEach((k,v) -&gt; {
          HttpClient.asyncGet("https://fakeurl1.com/item/" + k, createCustomCallbackOne(k, mapper)); 
          // HttpClient is just a wrapper class for your standard OkHTTP3 calls, 
          // e.g. client.newcall(request).enqueue(callback);
          HttpClient.asyncGet("https://fakeurl2.com/item/" + k, createCustomCallbackTwo(k, mapper));
      });
  }
  
  
  private createCustomCallbackOne(String id, ObjectMapper mapper) {
      return new Callback() {
          @Override
          public void onResponse(Call call, Response response) throws IOException {
              if (response.isSuccessful()) {
                  try (ResponseBody body = response.body()) {
                      CustomObject co = mapOfObjects.get(id);
                      if (co != null) {
                          co.setFieldOne(mapper.readValue(body.byteStream(), FieldOne.class))); 
                      }                       
                  } // implicitly closes the response body                
              }    
          }
  
          @Override
          public void onFailure(Call call, IOException e) {
              // log error                
          }
      }
  }
  
  // createCustomCallbackTwo does more or less the same thing, 
  // just sets a different field and then performs another 
  // async GET in order to set an additional field
  </code></pre>
  
  <p>So what would be the best/correct way to monitor all these asynchronous calls to ensure they have completed and I can go about performing another method on the Objects stored inside the map?</p>