List of usage examples for java.util.concurrent CompletionStage whenComplete
public CompletionStage<T> whenComplete(BiConsumer<? super T, ? super Throwable> action);
From source file:fi.minedu.oiva.backend.spring.handler.CompletionStageReturnValueHandler.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2s.c o m public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); return; } final DeferredResult<Object> deferredResult = new DeferredResult<>(); WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer); CompletionStage<?> future = (CompletionStage<?>) returnValue; future.whenComplete((result, ex) -> { if (ex != null) { deferredResult.setErrorResult(ex); } else { deferredResult.setResult(result); } }); }