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.187 by dl, Fri Apr 8 10:36:41 2016 UTC vs.
Revision 1.188 by jsr166, Mon Apr 18 18:07:54 2016 UTC

# Line 539 | Line 539 | public class CompletableFuture<T> implem
539          final boolean isLive() { return dep != null; }
540      }
541  
542 <    /** Pushes the given completion (if it exists) unless done. */
543 <    final void push(UniCompletion<?,?> c) {
542 >    /**
543 >     * Pushes the given completion unless it completes while trying.
544 >     * Caller should have first checked that result is null.
545 >     */
546 >    final void unipush(UniCompletion<?,?> c) {
547          if (c != null) {
548 <            while (result == null && !tryPushStack(c))
549 <                lazySetNext(c, null); // clear on failure
548 >            while (!tryPushStack(c)) {
549 >                if (result != null) {
550 >                    lazySetNext(c, null);
551 >                    break;
552 >                }
553 >            }
554 >            if (result != null)
555 >                c.tryFire(SYNC);
556          }
557      }
558  
# Line 627 | Line 636 | public class CompletableFuture<T> implem
636                  }
637              }
638              else {
639 <                push(c);
631 <                c.tryFire(SYNC);
639 >                unipush(c);
640              }
641          }
642          return d;
# Line 691 | Line 699 | public class CompletableFuture<T> implem
699                  }
700              }
701              else {
702 <                push(c);
695 <                c.tryFire(SYNC);
702 >                unipush(c);
703              }
704          }
705          return d;
# Line 748 | Line 755 | public class CompletableFuture<T> implem
755                  }
756              }
757              else {
758 <                push(c);
752 <                c.tryFire(SYNC);
758 >                unipush(c);
759              }
760          }
761          return d;
# Line 820 | Line 826 | public class CompletableFuture<T> implem
826                  }
827              }
828              else {
829 <                push(c);
824 <                c.tryFire(SYNC);
829 >                unipush(c);
830              }
831          }
832          return d;
# Line 885 | Line 890 | public class CompletableFuture<T> implem
890                  }
891              }
892              else {
893 <                push(c);
889 <                c.tryFire(SYNC);
893 >                unipush(c);
894              }
895          }
896          return d;
# Line 934 | Line 938 | public class CompletableFuture<T> implem
938          Function<Throwable, ? extends T> f) {
939          if (f == null) throw new NullPointerException();
940          CompletableFuture<T> d = newIncompleteFuture();
941 <        if (!d.uniExceptionally(this, f, null)) {
942 <            UniExceptionally<T> c = new UniExceptionally<T>(d, this, f);
939 <            push(c);
940 <            c.tryFire(SYNC);
941 <        }
941 >        if (!d.uniExceptionally(this, f, null))
942 >            unipush(new UniExceptionally<T>(d, this, f));
943          return d;
944      }
945  
# Line 971 | Line 972 | public class CompletableFuture<T> implem
972          if ((r = result) != null)
973              d.completeRelay(r);
974          else {
975 <            UniRelay<T> c = new UniRelay<T>(d, this);
975 <            push(c);
976 <            c.tryFire(SYNC);
975 >            unipush(new UniRelay<T>(d, this));
976          }
977          return d;
978      }
# Line 983 | Line 982 | public class CompletableFuture<T> implem
982          if ((r = result) != null)
983              return new MinimalStage<T>(encodeRelay(r));
984          MinimalStage<T> d = new MinimalStage<T>();
985 <        UniRelay<T> c = new UniRelay<T>(d, this);
987 <        push(c);
988 <        c.tryFire(SYNC);
985 >        unipush(new UniRelay<T>(d, this));
986          return d;
987      }
988  
# Line 1028 | Line 1025 | public class CompletableFuture<T> implem
1025                  @SuppressWarnings("unchecked") S s = (S) r;
1026                  CompletableFuture<T> g = f.apply(s).toCompletableFuture();
1027                  if (g.result == null || !uniRelay(g)) {
1028 <                    UniRelay<T> copy = new UniRelay<T>(this, g);
1032 <                    g.push(copy);
1033 <                    copy.tryFire(SYNC);
1028 >                    g.unipush(new UniRelay<T>(this, g));
1029                      if (result == null)
1030                          return false;
1031                  }
# Line 1060 | Line 1055 | public class CompletableFuture<T> implem
1055                  if ((s = g.result) != null)
1056                      d.completeRelay(s);
1057                  else {
1058 <                    UniRelay<V> c = new UniRelay<V>(d, g);
1064 <                    g.push(c);
1065 <                    c.tryFire(SYNC);
1058 >                    g.unipush(new UniRelay<V>(d, g));
1059                  }
1060                  return d;
1061              } catch (Throwable ex) {
# Line 1070 | Line 1063 | public class CompletableFuture<T> implem
1063                  return d;
1064              }
1065          }
1073        UniCompose<T,V> c = new UniCompose<T,V>(e, d, this, f);
1066          if (r != null && e != null) {
1067              try {
1068                  e.execute(new UniCompose<T,V>(null, d, this, f));
# Line 1079 | Line 1071 | public class CompletableFuture<T> implem
1071              }
1072          }
1073          else {
1074 <            push(c);
1083 <            c.tryFire(SYNC);
1074 >            unipush(new UniCompose<T,V>(e, d, this, f));
1075          }
1076          return d;
1077      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines