Skip to content

Instantly share code, notes, and snippets.

@edreyer
Last active July 15, 2020 15:10
Show Gist options
  • Save edreyer/019c7133fa949f2452aff75f41b96930 to your computer and use it in GitHub Desktop.
Save edreyer/019c7133fa949f2452aff75f41b96930 to your computer and use it in GitHub Desktop.
Spring Boot @async and Exceptions
import io.vavr.control.Try;
import java.util.concurrent.Future;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
class Foo {}
interface FooService {
/** Returns Future<Try<T>> for better exception handling */
@Async
Future<Try<Foo>> getFoo();
}
class FooServiceImpl implements FooService {
@Override
public Future<Try<Foo>> getFoo() {
return AsyncResult.forValue(Try.of(Foo::new));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment