title: Waiting for callback for multiple futures
body: <p>Recently I've delved into a little bit of work using an API. The API uses the Unirest http library to simplify the work of receiving from the web. Naturally, since the data is called from the API server, I tried to be efficient by using asynchronous calls to the API. My idea is structured as follows:</p>
  
  <ol>
  <li>Create array of data by returning the results of futures</li>
  <li>Display data + additional information gathered from the data</li>
  </ol>
  
  <p>Therefore, I need to have all the data returned before I can start the second step. My code is as follows:</p>
  
  <pre><code>Future &lt; HttpResponse &lt; JsonNode &gt;  &gt; future1 = Unirest.get("https://example.com/api").asJsonAsync(new Callback &lt; JsonNode &gt; () {
      public void failed(UnirestException e) {
          System.out.println("The request has failed");
      }
      public void completed(HttpResponse &lt; JsonNode &gt; response) {
          System.out.println(response.getBody().toString());
          responses.put(response);
      }
      public void cancelled() {
          System.out.println("The request has been cancelled");
      }
  });
  Future &lt; HttpResponse &lt; JsonNode &gt;  &gt; future2 = Unirest.get("https://example.com/api").asJsonAsync(new Callback &lt; JsonNode &gt; () {
      public void failed(UnirestException e) {
          System.out.println("The request has failed");
      }
      public void completed(HttpResponse &lt; JsonNode &gt; response) {
          System.out.println(response.getBody().toString());
          responses.put(response);
      }
      public void cancelled() {
          System.out.println("The request has been cancelled");
      }
  });
  doStuff(responses);
  </code></pre>
  
  <p>How would I make it so doStuff is called only after both of the futures are finished?</p>