Description: Preserves the Futures method removed in Guava 26 Author: Emmanuel Bourg Forwarded: not-needed --- a/guava/src/com/google/common/util/concurrent/Futures.java +++ b/guava/src/com/google/common/util/concurrent/Futures.java @@ -1056,6 +1056,52 @@ * computation is {@linkplain java.util.concurrent.Future#isDone() complete} or, if the * computation is already complete, immediately. * + *

There is no guaranteed ordering of execution of callbacks, but any callback added through + * this method is guaranteed to be called once the computation is complete. + * + *

Example: + * + *

{@code
+   * ListenableFuture future = ...;
+   * addCallback(future,
+   *     new FutureCallback() {
+   *       public void onSuccess(QueryResult result) {
+   *         storeInCache(result);
+   *       }
+   *       public void onFailure(Throwable t) {
+   *         reportError(t);
+   *       }
+   *     });
+   * }
+ * + *

This overload, which does not accept an executor, uses {@code directExecutor}, a dangerous + * choice in some cases. See the discussion in the {@link ListenableFuture#addListener + * ListenableFuture.addListener} documentation. All its warnings about heavyweight listeners are + * also applicable to heavyweight callbacks passed to this method. + * + *

For a more general interface to attach a completion listener to a {@code Future}, see {@link + * ListenableFuture#addListener addListener}. + * + * @param future The future attach the callback to. + * @param callback The callback to invoke when {@code future} is completed. + * @since 10.0 + * @deprecated Use {@linkplain #addCallback(ListenableFuture, FutureCallback, Executor) the + * overload that requires an executor}. For identical behavior, pass {@link + * MoreExecutors#directExecutor}, but consider whether another executor would be safer, as + * discussed in the {@link ListenableFuture#addListener ListenableFuture.addListener} + * documentation. This method is scheduled to be removed in July 2018. + */ + @Deprecated + public static void addCallback( + ListenableFuture future, FutureCallback callback) { + addCallback(future, callback, directExecutor()); + } + + /** + * Registers separate success and failure callbacks to be run when the {@code Future}'s + * computation is {@linkplain java.util.concurrent.Future#isDone() complete} or, if the + * computation is already complete, immediately. + * *

The callback is run on {@code executor}. There is no guaranteed ordering of execution of * callbacks, but any callback added through this method is guaranteed to be called once the * computation is complete.