How to wait for the value from onSuccess

Question from Stefan.lnd#2296

How do I make sure that java waits for the value from the onSucces method: https://pastebin.com/TR6ea2QZ ? (I cut out the irrelevant stuff)

public float getMoney(Player player){
      Float[] money = new Float[1];

      try {
          //SOME CODE FOR DB
          asyncMySQL.getMoneyAsnyc(statement, new Callback<Float>() {
             
              @Override
              public Float onSucces(Float money) {
                  //This value should be returned!!!
                  money[0] = money;
              }

              @Override
              public void onFailure(Throwable cause) {

              }
          });

      } catch (SQLException e) {
          e.printStackTrace();
      }
      return money[0];
  }

I want to call out that, long term, it;s going to be a better tech investment to use blocking sql because loom, but yes, you can return a Future

public class FutureExample {
    interface ExampleAsync {
        void onSuccess(float money);
        void onFailure(Throwable throwable);
    }
    
    private void someThing(ExampleAsync exampleAsync) {}
    
    public Future<Float> getMoney() {
        final var future = new CompletableFuture<Float>();
        try {
            someThing(new ExampleAsync() {
                @Override
                public void onSuccess(float money) {
                    future.complete(money);
                }

                @Override
                public void onFailure(Throwable throwable) {
                    future.completeExceptionally(throwable);
                }
            });
        } catch (Exception e) {
            future.completeExceptionally(e);
        }
        return future;
    }
}

<- Index