code: public void waitTask(String taskID, long timeToWait, RequestOptions requestOptions) throws AlgoliaException {
      try {
        while (true) {
          JSONObject obj = client.getRequest("/1/indexes/" + encodedIndexName + "/task/" + URLEncoder.encode(taskID, "UTF-8"), false, requestOptions);
          if (obj.getString("status").equals("published"))
            return;
          try {
            Thread.sleep(timeToWait);
          } catch (InterruptedException ignored) {
          }
          timeToWait *= 2;
          timeToWait = timeToWait > MAX_TIME_MS_TO_WAIT ? MAX_TIME_MS_TO_WAIT : timeToWait;
        }
      } catch (JSONException e) {
        throw new AlgoliaException(e.getMessage());
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
    }
docs: Wait the publication of a task on the server.
  All server task are asynchronous and you can check with this method that the task is published.
  
  @param taskID         the id of the task returned by server
  @param timeToWait     time to sleep seed
  @param requestOptions Options to pass to this request