ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/CompletableFuture.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/CompletableFuture.java (file contents):
Revision 1.90 by jsr166, Wed Jul 3 16:58:12 2013 UTC vs.
Revision 1.91 by dl, Fri Jul 5 15:47:15 2013 UTC

# Line 36 | Line 36 | import java.util.concurrent.locks.LockSu
36   * {@link #cancel cancel}
37   * a CompletableFuture, only one of them succeeds.
38   *
39 < * <p>CompletableFuture implements {@link CompletionStage} with the
40 < * following policies: <ul>
39 > * <p>In addition to these and related methods for directly
40 > * manipulating status and results, CompletableFuture implements
41 > * interface {@link CompletionStage} with the following policies: <ul>
42   *
43   * <li>Actions supplied for dependent completions of
44   * <em>non-async</em> methods may be performed by the thread that
# Line 54 | Line 55 | import java.util.concurrent.locks.LockSu
55   * other public methods, so the behavior of one method is not impacted
56   * by overrides of others in subclasses.  </li> </ul>
57   *
58 < * <p>CompletableFuture implements {@link Future} with the following
58 > * <p>CompletableFuture also implements {@link Future} with the following
59   * policies: <ul>
60   *
61   * <li>Since (unlike {@link FutureTask}) this class has no direct
# Line 584 | Line 585 | public class CompletableFuture<T> implem
585          private static final long serialVersionUID = 5232453952276885070L;
586      }
587  
588 +    static final class AsyncWhenComplete<T> extends Async {
589 +        final T arg1;
590 +        final Throwable arg2;
591 +        final BiConsumer<? super T,? super Throwable> fn;
592 +        final CompletableFuture<T> dst;
593 +        AsyncWhenComplete(T arg1, Throwable arg2,
594 +                          BiConsumer<? super T,? super Throwable> fn,
595 +                          CompletableFuture<T> dst) {
596 +            this.arg1 = arg1; this.arg2 = arg2; this.fn = fn; this.dst = dst;
597 +        }
598 +        public final boolean exec() {
599 +            CompletableFuture<T> d;
600 +            if ((d = this.dst) != null && d.result == null) {
601 +                Throwable ex = arg2;
602 +                try {
603 +                    fn.accept(arg1, ex);
604 +                } catch (Throwable rex) {
605 +                    if (ex == null)
606 +                        ex = rex;
607 +                }
608 +                d.internalComplete(arg1, ex);
609 +            }
610 +            return true;
611 +        }
612 +        private static final long serialVersionUID = 5232453952276885070L;
613 +    }
614 +
615      /* ------------- Completions -------------- */
616  
617      /**
# Line 1219 | Line 1247 | public class CompletableFuture<T> implem
1247                  Throwable dx = null;
1248                  try {
1249                      if (e != null)
1250 <                        e.execute(new AsyncAcceptBoth<T,Throwable>(t, ex, fn, dst));
1250 >                        e.execute(new AsyncWhenComplete<T>(t, ex, fn, dst));
1251                      else
1252                          fn.accept(t, ex);
1253                  } catch (Throwable rex) {
# Line 1332 | Line 1360 | public class CompletableFuture<T> implem
1360                  }
1361                  if (e == null || dx != null)
1362                      dst.internalComplete(u, dx);
1335                dst.internalComplete(u, dx);
1363              }
1364          }
1365          private static final long serialVersionUID = 5232453952276885070L;
# Line 1970 | Line 1997 | public class CompletableFuture<T> implem
1997              Throwable dx = null;
1998              try {
1999                  if (e != null)
2000 <                    e.execute(new AsyncAcceptBoth<T,Throwable>(t, ex, fn, dst));
2000 >                    e.execute(new AsyncWhenComplete<T>(t, ex, fn, dst));
2001                  else
2002                      fn.accept(t, ex);
2003              } catch (Throwable rex) {
# Line 2026 | Line 2053 | public class CompletableFuture<T> implem
2053              }
2054              if (e == null || dx != null)
2055                  dst.internalComplete(u, dx);
2029            dst.internalComplete(u, dx);
2056          }
2057          helpPostComplete();
2058          return dst;
# Line 2835 | Line 2861 | public class CompletableFuture<T> implem
2861  
2862      /**
2863       * Returns {@code true} if this CompletableFuture completed
2864 <     * exceptionally.
2864 >     * exceptionally, in any way. Possible causes include
2865 >     * cancellation, explicit invocation of {@code
2866 >     * completeExceptionally}, and abrupt termination of a
2867 >     * CompletionStage action.
2868       *
2869       * @return {@code true} if this CompletableFuture completed
2870       * exceptionally
2871       */
2872      public boolean isCompletedExceptionally() {
2873 <        return (result instanceof AltResult);
2873 >        Object r;
2874 >        return ((r = result) instanceof AltResult) && r != NIL;
2875      }
2876  
2877      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines