Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit e152cfd

Browse files
lukesandbergcpovirk
authored andcommitted
Rewrite nonCancellationPropagating to take advantage of setFuture
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=81244943
1 parent c239c19 commit e152cfd

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

guava/src/com/google/common/util/concurrent/Futures.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,20 +1046,11 @@ public static <V> ListenableFuture<V> nonCancellationPropagating(
10461046
private static class NonCancellationPropagatingFuture<V>
10471047
extends AbstractFuture<V> {
10481048
NonCancellationPropagatingFuture(final ListenableFuture<V> delegate) {
1049-
checkNotNull(delegate);
1050-
addCallback(delegate, new FutureCallback<V>() {
1051-
@Override
1052-
public void onSuccess(V result) {
1053-
set(result);
1054-
}
1055-
1056-
@Override
1057-
public void onFailure(Throwable t) {
1058-
if (delegate.isCancelled()) {
1059-
cancel(false);
1060-
} else {
1061-
setException(t);
1062-
}
1049+
delegate.addListener(new Runnable() {
1050+
@Override public void run() {
1051+
// This prevents cancellation from propagating because we don't assign delegate until
1052+
// delegate is already done, so calling cancel() on it is a no-op.
1053+
setFuture(delegate);
10631054
}
10641055
}, directExecutor());
10651056
}

0 commit comments

Comments
 (0)