@Override
  public T await() throws ApiException, IOException, InterruptedException {
    // Handle sleeping for retried requests
    if (retryCounter > 0) {
      // 0.5 * (1.5 ^ i) represents an increased sleep time of 1.5x per iteration,
      // starting at 0.5s when i = 0. The retryCounter will be 1 for the 1st retry,
      // so subtract 1 here.
      double delaySecs = 0.5 * Math.pow(1.5, retryCounter - 1);

      // Generate a jitter value between -delaySecs / 2 and +delaySecs / 2
      long delayMillis = (long) (delaySecs * (Math.random() + 0.5) * 1000);

      LOG.debug(
          String.format(
              "Sleeping between errors for %dms (retry #%d, already slept %dms)",
              delayMillis, retryCounter, cumulativeSleepTime));
      cumulativeSleepTime += delayMillis;
      try {
        Thread.sleep(delayMillis);
      } catch (InterruptedException e) {
        // No big deal if we don't sleep as long as intended.
      }
    }

    final BlockingQueue<QueuedResponse> waiter = new ArrayBlockingQueue<>(1);
    final OkHttpPendingResult<T, R> parent = this;

    // This callback will be called on another thread, handled by the RateLimitExecutorService.
    // Calling call.execute() directly would bypass the rate limiting.
    call.enqueue(
        new okhttp3.Callback() {
          @Override
          public void onFailure(Call call, IOException e) {
            metrics.endNetwork();
            waiter.add(new QueuedResponse(parent, e));
          }

          @Override
          public void onResponse(Call call, Response response) throws IOException {
            metrics.endNetwork();
            waiter.add(new QueuedResponse(parent, response));
          }
        });

    QueuedResponse r = waiter.take();
    if (r.response != null) {
      return parseResponse(r.request, r.response);
    } else {
      metrics.endRequest(r.e, 0, retryCounter);
      throw r.e;
    }
  }
Preserve a request/response pair through an asynchronous callback.
src/main/java/com/google/maps/internal/OkHttpPendingResult.java