I am trying to convert a blocking Play framework controller action that looks like this:
public Result testSync(String param1, String param2) {
String result1 = <LONG-DB-QUERY>;
if (result1 == null) {
return internalServerError();
}
if (result1.equals("<SOME VALUE>")) {
return ok(param1);
}
String result2 = <LONG-DB-QUERY>;
return ok(result1 + result2);
}
into non blocking code using the Future
interface, i.e. returning a CompletionStage<Result>
As you see I need both result1
and result2
. I assume that I cannot use supplyAsync
and thenCombine
because result2
needs to be calculated only under certain circumstances.