Returning common Result as CompletionStage<Result> in play
<p>In my view function I may return a <code>Result</code> or a <code>CompletionStage&lt;Result&gt;</code> based on whether or not the post/get data is valid or not:</p>

<pre><code>if (data.hasErrors()) {
    return badRequest(myview.render(data));
} else {
    return CompletableFuture.supplyAsync(() -&gt; calculate(data)
                .thenApply(result -&gt; ok("Got result: " + result.toString()));
}
</code></pre>

<p>The problem is that I can't have the view function return both types, so it seems logical to return the async version and somehow wrap the <code>badRequest</code> (or any other common response in <code>play.mvc.Results</code>) in a <code>CompletableFuture</code>.</p>

<p>I can do something like:</p>

<pre><code>return CompletableFuture.supplyAsync(() -&gt; "")
            .thenApply(result -&gt; badRequest(myview.render(data)));
</code></pre>

<p>But I'm hoping for a more elegant solution.<br>
Anything?</p>

<p>I'm using play version 2.5.4.</p>