I am calling a service that returns CompletableFuture.
The output structure is as follows.
Class Output {
public String name;
public Integer age;
}
And I want to make a call for service, and I want to continue execution until the name appears.
Sort of,
CompletableFuture<Output> futureOutput = makeServiceCall(input);
String name = futureOutput.get().name;
processName(name);
In the above approach, I need to wait until mine futureOutputis ready, although I need it only later.
I am looking for something like an approach below.
CompletableFuture<Output> futureOutput = makeServiceCall(input);
CompletableFuture<String> futureName = futureOutput.get().name;
processName(futureName);
It’s good for me to change the signature processNamefrom Stringto CompletableFuture<String>, but not to CompletableFuture<Output>, because Outputit makes no sense for this method.
What are the suggested ways to have a future link that is a field of the future.