Closed
Description
Returning a value from an @Async
method usually involves a CompletableFuture
wrapper of the value. If such a method is declared like this:
@Async
@Transactional
CompletableFuture<…> doSomething() {
return someCondition
? CompletableFuture.completedFuture(…)
: CompletedFuture.failedFuture(…);
}
The failed CF
could be the result of handling an exception as we might not want to bubble up the async execution exception handling chain, but rather hand into the client so that it can react to the failure by e.g. ….exceptionally(…)
.
Unfortunately, for transactional methods, returning that failed CF
instance would not roll back the transaction, as that currently only reacts to exceptions being thrown and Vavr Failure
instances. Failed CF
instances are actually very similar to the latter, which is why it would be nice if our transaction handling worked the same when returning failed CF
s.