I'm looking for the best way, in Java, to asynchronously run some tasks calculating some values and when they're all gathered, run some further calculation on them.
I thought I was going down the right path with this
var f1 = CompletableFuture.supplyAsync(() -> Service.findPlayers(filter, maxCount, LeaderboardType.Unranked));
var f2 = CompletableFuture.supplyAsync(() -> Service.findPlayers(filter, maxCount, LeaderboardType._1x1_RM));
var f3 = CompletableFuture.supplyAsync(() -> Service.findPlayers(filter, maxCount, LeaderboardType.TG_RM));
var x = CompletableFuture.allOf(f1, f2, f3);
until I realized that unfortunately allOf()
doesn't return a list with the results of f1
, f2
and f3
but void
instead? Is there any alternative? Otherwise I'd have to store the results in some sort of "global variable" and then access them from the when()
call, which completely defeats the whole purpose of using supplyAync
vs runAsync
, I guess.