我意识到我希望我们 API 的使用者不必处理异常。或者更清楚地说,我想确保始终记录异常,但只有消费者知道如何处理成功。如果客户愿意,我希望客户也能够处理异常File,我无法返回给他们。
注:FileDownload是一个Supplier<File>
@Override
public CompletableFuture<File> processDownload( final FileDownload fileDownload ) {
Objects.requireNonNull( fileDownload );
fileDownload.setDirectory( getTmpDirectoryPath() );
CompletableFuture<File> future = CompletableFuture.supplyAsync( fileDownload, executorService );
future... throwable -> {
if ( throwable != null ) {
logError( throwable );
}
...
return null; // client won't receive file.
} );
return future;
}
我真的不明白这些CompletionStage东西。我使用exceptionorhandle吗?我返回原来的未来还是他们返回的未来?