code: @Override
    public void waitForOperation(Operation operation, long timeout, TimeUnit timeUnit)
        throws TimeoutException, IOException {
      GetOperationRequest request = GetOperationRequest.newBuilder()
          .setName(operation.getName())
          .build();
  
      ExponentialBackOff backOff = new ExponentialBackOff.Builder()
          .setInitialIntervalMillis(100)
          .setMultiplier(1.3)
          .setMaxIntervalMillis(Ints.checkedCast(TimeUnit.SECONDS.toMillis(60)))
          .setMaxElapsedTimeMillis(Ints.checkedCast(timeUnit.toMillis(timeout)))
          .build();
  
      Operation currentOperationState = operation;
  
      while (true) {
        if (currentOperationState.getDone()) {
          switch (currentOperationState.getResultCase()) {
            case RESPONSE:
              return;
            case ERROR:
              throw StatusProto.toStatusRuntimeException(currentOperationState.getError());
            case RESULT_NOT_SET:
              throw new IllegalStateException(
                  "System returned invalid response for Operation check: " + currentOperationState);
          }
        }
  
        final long backOffMillis;
        try {
          backOffMillis = backOff.nextBackOffMillis();
        } catch (IOException e) {
          // Should never happen.
          throw new RuntimeException(e);
        }
        if (backOffMillis == BackOff.STOP) {
          throw new TimeoutException("Operation did not complete in time");
        } else {
          try {
            Thread.sleep(backOffMillis);
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IOException("Interrupted while waiting for operation to finish");
          }
        }
  
        currentOperationState = getOperation(request);
      }
    }
docs: {@inheritDoc}