I have code:
final ActorSystem system = ActorSystem.create(“test-stream”);
final Materializer mat = ActorMaterializer.create(system);
final Source<Integer, NotUsed> source = Source.range(1, 100);
final Sink<Integer, CompletionStage> sinkTotal = Sink.fold(0, (aggr, next) → { return aggr + next;});
final RunnableGraph<CompletionStage> graph = source.toMat(sinkTotal, Keep.right());
final CompletionStage sum = graph.run(mat);
int total = sum.toCompletableFuture().get());
To get the final sum value, I need to do:
sum.toCompletableFuture().get();
But get() method is blocking.
How can I access the final value without blocking the main thread?