docs: private void connect(int attempt, CompletableFuture<SessionClient> future) {
      if (attempt > MAX_ATTEMPTS) {
        future.completeExceptionally(new PrimitiveException.Unavailable());
        return;
      }
  
      primaryElection.getTerm().whenCompleteAsync((term, error) -> {
        if (error == null) {
          if (term.primary() == null) {
            future.completeExceptionally(new PrimitiveException.Unavailable());
          } else {
            this.term = term;
            protocol.registerEventListener(sessionId, this::handleEvent, threadContext);
            future.complete(this);
          }
        } else {
          Throwable cause = Throwables.getRootCause(error);
          if (cause instanceof PrimitiveException.Unavailable || cause instanceof TimeoutException) {
            threadContext.schedule(Duration.ofMillis(RETRY_DELAY), () -> connect(attempt + 1, future));
          } else {
            future.completeExceptionally(new PrimitiveException.Unavailable());
          }
        }
      }, threadContext);
    }