573 |
|
final CompletableFuture<V> tryFire(int mode) { |
574 |
|
CompletableFuture<V> d; CompletableFuture<T> a; |
575 |
|
Object r; Throwable x; Function<? super T,? extends V> f; |
576 |
< |
if ((a = src) == null |
577 |
< |
|| (r = a.result) == null |
578 |
< |
|| (d = dep) == null |
579 |
< |
|| (f = fn) == null) |
576 |
> |
if ((d = dep) == null || (f = fn) == null |
577 |
> |
|| (a = src) == null || (r = a.result) == null) |
578 |
|
return null; |
579 |
|
tryComplete: if (d.result == null) { |
580 |
|
if (r instanceof AltResult) { |
617 |
|
CompletableFuture<V> d = newIncompleteFuture(); |
618 |
|
if (r instanceof AltResult) { |
619 |
|
if ((x = ((AltResult)r).ex) != null) { |
620 |
< |
d.completeThrowable(x, r); |
620 |
> |
d.result = encodeThrowable(x, r); |
621 |
|
return d; |
622 |
|
} |
623 |
|
r = null; |
627 |
|
e.execute(new UniApply<T,V>(null, d, this, f)); |
628 |
|
} else { |
629 |
|
@SuppressWarnings("unchecked") T t = (T) r; |
630 |
< |
d.completeValue(f.apply(t)); |
630 |
> |
d.result = d.encodeValue(f.apply(t)); |
631 |
|
} |
632 |
|
} catch (Throwable ex) { |
633 |
< |
d.completeThrowable(ex); |
633 |
> |
d.result = encodeThrowable(ex); |
634 |
|
} |
635 |
|
return d; |
636 |
|
} |
645 |
|
final CompletableFuture<Void> tryFire(int mode) { |
646 |
|
CompletableFuture<Void> d; CompletableFuture<T> a; |
647 |
|
Object r; Throwable x; Consumer<? super T> f; |
648 |
< |
if ((a = src) == null |
649 |
< |
|| (r = a.result) == null |
652 |
< |
|| (d = dep) == null |
653 |
< |
|| (f = fn) == null) |
648 |
> |
if ((d = dep) == null || (f = fn) == null |
649 |
> |
|| (a = src) == null || (r = a.result) == null) |
650 |
|
return null; |
651 |
|
tryComplete: if (d.result == null) { |
652 |
|
if (r instanceof AltResult) { |
690 |
|
CompletableFuture<Void> d = newIncompleteFuture(); |
691 |
|
if (r instanceof AltResult) { |
692 |
|
if ((x = ((AltResult)r).ex) != null) { |
693 |
< |
d.completeThrowable(x, r); |
693 |
> |
d.result = encodeThrowable(x, r); |
694 |
|
return d; |
695 |
|
} |
696 |
|
r = null; |
701 |
|
} else { |
702 |
|
@SuppressWarnings("unchecked") T t = (T) r; |
703 |
|
f.accept(t); |
704 |
< |
d.completeNull(); |
704 |
> |
d.result = NIL; |
705 |
|
} |
706 |
|
} catch (Throwable ex) { |
707 |
< |
d.completeThrowable(ex); |
707 |
> |
d.result = encodeThrowable(ex); |
708 |
|
} |
709 |
|
return d; |
710 |
|
} |
719 |
|
final CompletableFuture<Void> tryFire(int mode) { |
720 |
|
CompletableFuture<Void> d; CompletableFuture<T> a; |
721 |
|
Object r; Throwable x; Runnable f; |
722 |
< |
if ((a = src) == null |
723 |
< |
|| (r = a.result) == null |
728 |
< |
|| (d = dep) == null |
729 |
< |
|| (f = fn) == null) |
722 |
> |
if ((d = dep) == null || (f = fn) == null |
723 |
> |
|| (a = src) == null || (r = a.result) == null) |
724 |
|
return null; |
725 |
|
if (d.result == null) { |
726 |
|
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) |
756 |
|
Throwable x; |
757 |
|
CompletableFuture<Void> d = newIncompleteFuture(); |
758 |
|
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) |
759 |
< |
d.completeThrowable(x, r); |
759 |
> |
d.result = encodeThrowable(x, r); |
760 |
|
else |
761 |
|
try { |
762 |
|
if (e != null) { |
763 |
|
e.execute(new UniRun<T>(null, d, this, f)); |
764 |
|
} else { |
765 |
|
f.run(); |
766 |
< |
d.completeNull(); |
766 |
> |
d.result = NIL; |
767 |
|
} |
768 |
|
} catch (Throwable ex) { |
769 |
< |
d.completeThrowable(ex); |
769 |
> |
d.result = encodeThrowable(ex); |
770 |
|
} |
771 |
|
return d; |
772 |
|
} |
781 |
|
} |
782 |
|
final CompletableFuture<T> tryFire(int mode) { |
783 |
|
CompletableFuture<T> d; CompletableFuture<T> a; |
784 |
< |
if ((d = dep) == null || |
785 |
< |
!d.uniWhenComplete(a = src, fn, mode > 0 ? null : this)) |
784 |
> |
Object r; BiConsumer<? super T, ? super Throwable> f; |
785 |
> |
if ((d = dep) == null || (f = fn) == null |
786 |
> |
|| (a = src) == null || (r = a.result) == null |
787 |
> |
|| !d.uniWhenComplete(r, f, mode > 0 ? null : this)) |
788 |
|
return null; |
789 |
|
dep = null; src = null; fn = null; |
790 |
|
return d.postFire(a, mode); |
791 |
|
} |
792 |
|
} |
793 |
|
|
794 |
< |
final boolean uniWhenComplete(CompletableFuture<T> a, |
794 |
> |
final boolean uniWhenComplete(Object r, |
795 |
|
BiConsumer<? super T,? super Throwable> f, |
796 |
|
UniWhenComplete<T> c) { |
797 |
< |
Object r; T t; Throwable x = null; |
802 |
< |
if (a == null || (r = a.result) == null || f == null) |
803 |
< |
return false; |
797 |
> |
T t; Throwable x = null; |
798 |
|
if (result == null) { |
799 |
|
try { |
800 |
|
if (c != null && !c.claim()) |
826 |
|
Executor e, BiConsumer<? super T, ? super Throwable> f) { |
827 |
|
if (f == null) throw new NullPointerException(); |
828 |
|
CompletableFuture<T> d = newIncompleteFuture(); |
829 |
< |
if (e != null || !d.uniWhenComplete(this, f, null)) { |
830 |
< |
UniWhenComplete<T> c = new UniWhenComplete<T>(e, d, this, f); |
831 |
< |
if (e != null && result != null) { |
832 |
< |
try { |
833 |
< |
e.execute(c); |
834 |
< |
} catch (Throwable ex) { |
835 |
< |
d.completeThrowable(ex); |
836 |
< |
} |
837 |
< |
} |
838 |
< |
else { |
845 |
< |
unipush(c); |
829 |
> |
Object r; |
830 |
> |
if ((r = result) == null) |
831 |
> |
unipush(new UniWhenComplete<T>(e, d, this, f)); |
832 |
> |
else if (e == null) |
833 |
> |
d.uniWhenComplete(r, f, null); |
834 |
> |
else { |
835 |
> |
try { |
836 |
> |
e.execute(new UniWhenComplete<T>(null, d, this, f)); |
837 |
> |
} catch (Throwable ex) { |
838 |
> |
d.result = encodeThrowable(ex); |
839 |
|
} |
840 |
|
} |
841 |
|
return d; |
851 |
|
} |
852 |
|
final CompletableFuture<V> tryFire(int mode) { |
853 |
|
CompletableFuture<V> d; CompletableFuture<T> a; |
854 |
< |
if ((d = dep) == null || |
855 |
< |
!d.uniHandle(a = src, fn, mode > 0 ? null : this)) |
854 |
> |
Object r; BiFunction<? super T, Throwable, ? extends V> f; |
855 |
> |
if ((d = dep) == null || (f = fn) == null |
856 |
> |
|| (a = src) == null || (r = a.result) == null |
857 |
> |
|| !d.uniHandle(r, f, mode > 0 ? null : this)) |
858 |
|
return null; |
859 |
|
dep = null; src = null; fn = null; |
860 |
|
return d.postFire(a, mode); |
861 |
|
} |
862 |
|
} |
863 |
|
|
864 |
< |
final <S> boolean uniHandle(CompletableFuture<S> a, |
864 |
> |
final <S> boolean uniHandle(Object r, |
865 |
|
BiFunction<? super S, Throwable, ? extends T> f, |
866 |
|
UniHandle<S,T> c) { |
867 |
< |
Object r; S s; Throwable x; |
873 |
< |
if (a == null || (r = a.result) == null || f == null) |
874 |
< |
return false; |
867 |
> |
S s; Throwable x; |
868 |
|
if (result == null) { |
869 |
|
try { |
870 |
|
if (c != null && !c.claim()) |
889 |
|
Executor e, BiFunction<? super T, Throwable, ? extends V> f) { |
890 |
|
if (f == null) throw new NullPointerException(); |
891 |
|
CompletableFuture<V> d = newIncompleteFuture(); |
892 |
< |
if (e != null || !d.uniHandle(this, f, null)) { |
893 |
< |
UniHandle<T,V> c = new UniHandle<T,V>(e, d, this, f); |
894 |
< |
if (e != null && result != null) { |
895 |
< |
try { |
896 |
< |
e.execute(c); |
897 |
< |
} catch (Throwable ex) { |
898 |
< |
d.completeThrowable(ex); |
899 |
< |
} |
900 |
< |
} |
901 |
< |
else { |
909 |
< |
unipush(c); |
892 |
> |
Object r; |
893 |
> |
if ((r = result) == null) |
894 |
> |
unipush(new UniHandle<T,V>(e, d, this, f)); |
895 |
> |
else if (e == null) |
896 |
> |
d.uniHandle(r, f, null); |
897 |
> |
else { |
898 |
> |
try { |
899 |
> |
e.execute(new UniHandle<T,V>(null, d, this, f)); |
900 |
> |
} catch (Throwable ex) { |
901 |
> |
d.result = encodeThrowable(ex); |
902 |
|
} |
903 |
|
} |
904 |
|
return d; |
914 |
|
final CompletableFuture<T> tryFire(int mode) { // never ASYNC |
915 |
|
// assert mode != ASYNC; |
916 |
|
CompletableFuture<T> d; CompletableFuture<T> a; |
917 |
< |
if ((d = dep) == null || !d.uniExceptionally(a = src, fn, this)) |
917 |
> |
Object r; Function<? super Throwable, ? extends T> f; |
918 |
> |
if ((d = dep) == null || (f = fn) == null |
919 |
> |
|| (a = src) == null || (r = a.result) == null |
920 |
> |
|| !d.uniExceptionally(r, f, this)) |
921 |
|
return null; |
922 |
|
dep = null; src = null; fn = null; |
923 |
|
return d.postFire(a, mode); |
924 |
|
} |
925 |
|
} |
926 |
|
|
927 |
< |
final boolean uniExceptionally(CompletableFuture<T> a, |
927 |
> |
final boolean uniExceptionally(Object r, |
928 |
|
Function<? super Throwable, ? extends T> f, |
929 |
|
UniExceptionally<T> c) { |
930 |
< |
Object r; Throwable x; |
936 |
< |
if (a == null || (r = a.result) == null || f == null) |
937 |
< |
return false; |
930 |
> |
Throwable x; |
931 |
|
if (result == null) { |
932 |
|
try { |
933 |
|
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) { |
947 |
|
Function<Throwable, ? extends T> f) { |
948 |
|
if (f == null) throw new NullPointerException(); |
949 |
|
CompletableFuture<T> d = newIncompleteFuture(); |
950 |
< |
if (!d.uniExceptionally(this, f, null)) |
950 |
> |
Object r; |
951 |
> |
if ((r = result) == null) |
952 |
|
unipush(new UniExceptionally<T>(d, this, f)); |
953 |
+ |
else |
954 |
+ |
d.uniExceptionally(r, f, null); |
955 |
|
return d; |
956 |
|
} |
957 |
|
|
958 |
|
@SuppressWarnings("serial") |
959 |
< |
static final class UniRelay<T> extends UniCompletion<T,T> { // for Compose |
959 |
> |
static final class UniRelay<T> extends UniCompletion<T,T> { |
960 |
|
UniRelay(CompletableFuture<T> dep, CompletableFuture<T> src) { |
961 |
|
super(null, dep, src); |
962 |
|
} |
963 |
|
final CompletableFuture<T> tryFire(int mode) { |
964 |
< |
CompletableFuture<T> d; CompletableFuture<T> a; |
965 |
< |
if ((d = dep) == null || !d.uniRelay(a = src)) |
964 |
> |
CompletableFuture<T> d; CompletableFuture<T> a; Object r; |
965 |
> |
if ((d = dep) == null |
966 |
> |
|| (a = src) == null || (r = a.result) == null) |
967 |
|
return null; |
968 |
+ |
if (d.result == null) |
969 |
+ |
d.completeRelay(r); |
970 |
|
src = null; dep = null; |
971 |
|
return d.postFire(a, mode); |
972 |
|
} |
973 |
|
} |
974 |
|
|
976 |
– |
final boolean uniRelay(CompletableFuture<T> a) { |
977 |
– |
Object r; |
978 |
– |
if (a == null || (r = a.result) == null) |
979 |
– |
return false; |
980 |
– |
if (result == null) // no need to claim |
981 |
– |
completeRelay(r); |
982 |
– |
return true; |
983 |
– |
} |
984 |
– |
|
975 |
|
private CompletableFuture<T> uniCopyStage() { |
976 |
|
Object r; |
977 |
|
CompletableFuture<T> d = newIncompleteFuture(); |
978 |
|
if ((r = result) != null) |
979 |
< |
d.completeRelay(r); |
980 |
< |
else { |
979 |
> |
d.result = encodeRelay(r); |
980 |
> |
else |
981 |
|
unipush(new UniRelay<T>(d, this)); |
992 |
– |
} |
982 |
|
return d; |
983 |
|
} |
984 |
|
|
1001 |
|
} |
1002 |
|
final CompletableFuture<V> tryFire(int mode) { |
1003 |
|
CompletableFuture<V> d; CompletableFuture<T> a; |
1004 |
< |
if ((d = dep) == null || |
1005 |
< |
!d.uniCompose(a = src, fn, mode > 0 ? null : this)) |
1004 |
> |
Function<? super T, ? extends CompletionStage<V>> f; |
1005 |
> |
Object r; Throwable x; |
1006 |
> |
if ((d = dep) == null || (f = fn) == null |
1007 |
> |
|| (a = src) == null || (r = a.result) == null) |
1008 |
|
return null; |
1009 |
< |
dep = null; src = null; fn = null; |
1010 |
< |
return d.postFire(a, mode); |
1011 |
< |
} |
1012 |
< |
} |
1013 |
< |
|
1014 |
< |
final <S> boolean uniCompose( |
1015 |
< |
CompletableFuture<S> a, |
1025 |
< |
Function<? super S, ? extends CompletionStage<T>> f, |
1026 |
< |
UniCompose<S,T> c) { |
1027 |
< |
Object r; Throwable x; |
1028 |
< |
if (a == null || (r = a.result) == null || f == null) |
1029 |
< |
return false; |
1030 |
< |
tryComplete: if (result == null) { |
1031 |
< |
if (r instanceof AltResult) { |
1032 |
< |
if ((x = ((AltResult)r).ex) != null) { |
1033 |
< |
completeThrowable(x, r); |
1034 |
< |
break tryComplete; |
1009 |
> |
tryComplete: if (d.result == null) { |
1010 |
> |
if (r instanceof AltResult) { |
1011 |
> |
if ((x = ((AltResult)r).ex) != null) { |
1012 |
> |
d.completeThrowable(x, r); |
1013 |
> |
break tryComplete; |
1014 |
> |
} |
1015 |
> |
r = null; |
1016 |
|
} |
1017 |
< |
r = null; |
1018 |
< |
} |
1019 |
< |
try { |
1020 |
< |
if (c != null && !c.claim()) |
1021 |
< |
return false; |
1022 |
< |
@SuppressWarnings("unchecked") S s = (S) r; |
1023 |
< |
CompletableFuture<T> g = f.apply(s).toCompletableFuture(); |
1024 |
< |
if (g.result == null || !uniRelay(g)) { |
1025 |
< |
g.unipush(new UniRelay<T>(this, g)); |
1026 |
< |
if (result == null) |
1027 |
< |
return false; |
1017 |
> |
try { |
1018 |
> |
if (mode <= 0 && !claim()) |
1019 |
> |
return null; |
1020 |
> |
@SuppressWarnings("unchecked") T t = (T) r; |
1021 |
> |
CompletableFuture<V> g = f.apply(t).toCompletableFuture(); |
1022 |
> |
if ((r = g.result) != null) |
1023 |
> |
d.completeRelay(r); |
1024 |
> |
else { |
1025 |
> |
g.unipush(new UniRelay<V>(d, g)); |
1026 |
> |
if (d.result == null) |
1027 |
> |
return null; |
1028 |
> |
} |
1029 |
> |
} catch (Throwable ex) { |
1030 |
> |
d.completeThrowable(ex); |
1031 |
|
} |
1048 |
– |
} catch (Throwable ex) { |
1049 |
– |
completeThrowable(ex); |
1032 |
|
} |
1033 |
+ |
dep = null; src = null; fn = null; |
1034 |
+ |
return d.postFire(a, mode); |
1035 |
|
} |
1052 |
– |
return true; |
1036 |
|
} |
1037 |
|
|
1038 |
|
private <V> CompletableFuture<V> uniComposeStage( |
1039 |
|
Executor e, Function<? super T, ? extends CompletionStage<V>> f) { |
1040 |
|
if (f == null) throw new NullPointerException(); |
1058 |
– |
Object r, s; Throwable x; |
1041 |
|
CompletableFuture<V> d = newIncompleteFuture(); |
1042 |
< |
if ((r = result) != null && e == null) { |
1042 |
> |
Object r, s; Throwable x; |
1043 |
> |
if ((r = result) == null) |
1044 |
> |
unipush(new UniCompose<T,V>(e, d, this, f)); |
1045 |
> |
else if (e == null) { |
1046 |
|
if (r instanceof AltResult) { |
1047 |
|
if ((x = ((AltResult)r).ex) != null) { |
1048 |
|
d.result = encodeThrowable(x, r); |
1054 |
|
@SuppressWarnings("unchecked") T t = (T) r; |
1055 |
|
CompletableFuture<V> g = f.apply(t).toCompletableFuture(); |
1056 |
|
if ((s = g.result) != null) |
1057 |
< |
d.completeRelay(s); |
1057 |
> |
d.result = encodeRelay(s); |
1058 |
|
else { |
1059 |
|
g.unipush(new UniRelay<V>(d, g)); |
1060 |
|
} |
1076 |
– |
return d; |
1061 |
|
} catch (Throwable ex) { |
1062 |
|
d.result = encodeThrowable(ex); |
1079 |
– |
return d; |
1063 |
|
} |
1064 |
|
} |
1065 |
< |
if (r != null && e != null) { |
1065 |
> |
else |
1066 |
|
try { |
1067 |
|
e.execute(new UniCompose<T,V>(null, d, this, f)); |
1068 |
|
} catch (Throwable ex) { |
1069 |
< |
d.completeThrowable(ex); |
1069 |
> |
d.result = encodeThrowable(ex); |
1070 |
|
} |
1088 |
– |
} |
1089 |
– |
else { |
1090 |
– |
unipush(new UniCompose<T,V>(e, d, this, f)); |
1091 |
– |
} |
1071 |
|
return d; |
1072 |
|
} |
1073 |
|
|
1147 |
|
CompletableFuture<V> d; |
1148 |
|
CompletableFuture<T> a; |
1149 |
|
CompletableFuture<U> b; |
1150 |
< |
if ((d = dep) == null || |
1151 |
< |
!d.biApply(a = src, b = snd, fn, mode > 0 ? null : this)) |
1150 |
> |
Object r, s; BiFunction<? super T,? super U,? extends V> f; |
1151 |
> |
if ((d = dep) == null || (f = fn) == null |
1152 |
> |
|| (a = src) == null || (r = a.result) == null |
1153 |
> |
|| (b = snd) == null || (s = b.result) == null |
1154 |
> |
|| !d.biApply(r, s, f, mode > 0 ? null : this)) |
1155 |
|
return null; |
1156 |
|
dep = null; src = null; snd = null; fn = null; |
1157 |
|
return d.postFire(a, b, mode); |
1158 |
|
} |
1159 |
|
} |
1160 |
|
|
1161 |
< |
final <R,S> boolean biApply(CompletableFuture<R> a, |
1180 |
< |
CompletableFuture<S> b, |
1161 |
> |
final <R,S> boolean biApply(Object r, Object s, |
1162 |
|
BiFunction<? super R,? super S,? extends T> f, |
1163 |
|
BiApply<R,S,T> c) { |
1164 |
< |
Object r, s; Throwable x; |
1184 |
< |
if (a == null || (r = a.result) == null || |
1185 |
< |
b == null || (s = b.result) == null || f == null) |
1186 |
< |
return false; |
1164 |
> |
Throwable x; |
1165 |
|
tryComplete: if (result == null) { |
1166 |
|
if (r instanceof AltResult) { |
1167 |
|
if ((x = ((AltResult)r).ex) != null) { |
1193 |
|
private <U,V> CompletableFuture<V> biApplyStage( |
1194 |
|
Executor e, CompletionStage<U> o, |
1195 |
|
BiFunction<? super T,? super U,? extends V> f) { |
1196 |
< |
CompletableFuture<U> b; |
1196 |
> |
CompletableFuture<U> b; Object r, s; |
1197 |
|
if (f == null || (b = o.toCompletableFuture()) == null) |
1198 |
|
throw new NullPointerException(); |
1199 |
|
CompletableFuture<V> d = newIncompleteFuture(); |
1200 |
< |
if (e != null || !d.biApply(this, b, f, null)) { |
1201 |
< |
BiApply<T,U,V> c = new BiApply<T,U,V>(e, d, this, b, f); |
1202 |
< |
if (e != null && result != null && b.result != null) { |
1203 |
< |
try { |
1204 |
< |
e.execute(c); |
1205 |
< |
} catch (Throwable ex) { |
1206 |
< |
d.completeThrowable(ex); |
1207 |
< |
} |
1208 |
< |
} |
1231 |
< |
else { |
1232 |
< |
bipush(b, c); |
1200 |
> |
if ((r = result) == null || (s = b.result) == null) |
1201 |
> |
bipush(b, new BiApply<T,U,V>(e, d, this, b, f)); |
1202 |
> |
else if (e == null) |
1203 |
> |
d.biApply(r, s, f, null); |
1204 |
> |
else |
1205 |
> |
try { |
1206 |
> |
e.execute(new BiApply<T,U,V>(null, d, this, b, f)); |
1207 |
> |
} catch (Throwable ex) { |
1208 |
> |
d.result = encodeThrowable(ex); |
1209 |
|
} |
1234 |
– |
} |
1210 |
|
return d; |
1211 |
|
} |
1212 |
|
|
1222 |
|
CompletableFuture<Void> d; |
1223 |
|
CompletableFuture<T> a; |
1224 |
|
CompletableFuture<U> b; |
1225 |
< |
if ((d = dep) == null || |
1226 |
< |
!d.biAccept(a = src, b = snd, fn, mode > 0 ? null : this)) |
1225 |
> |
Object r, s; BiConsumer<? super T,? super U> f; |
1226 |
> |
if ((d = dep) == null || (f = fn) == null |
1227 |
> |
|| (a = src) == null || (r = a.result) == null |
1228 |
> |
|| (b = snd) == null || (s = b.result) == null |
1229 |
> |
|| !d.biAccept(r, s, f, mode > 0 ? null : this)) |
1230 |
|
return null; |
1231 |
|
dep = null; src = null; snd = null; fn = null; |
1232 |
|
return d.postFire(a, b, mode); |
1233 |
|
} |
1234 |
|
} |
1235 |
|
|
1236 |
< |
final <R,S> boolean biAccept(CompletableFuture<R> a, |
1259 |
< |
CompletableFuture<S> b, |
1236 |
> |
final <R,S> boolean biAccept(Object r, Object s, |
1237 |
|
BiConsumer<? super R,? super S> f, |
1238 |
|
BiAccept<R,S> c) { |
1239 |
< |
Object r, s; Throwable x; |
1263 |
< |
if (a == null || (r = a.result) == null || |
1264 |
< |
b == null || (s = b.result) == null || f == null) |
1265 |
< |
return false; |
1239 |
> |
Throwable x; |
1240 |
|
tryComplete: if (result == null) { |
1241 |
|
if (r instanceof AltResult) { |
1242 |
|
if ((x = ((AltResult)r).ex) != null) { |
1269 |
|
private <U> CompletableFuture<Void> biAcceptStage( |
1270 |
|
Executor e, CompletionStage<U> o, |
1271 |
|
BiConsumer<? super T,? super U> f) { |
1272 |
< |
CompletableFuture<U> b; |
1272 |
> |
CompletableFuture<U> b; Object r, s; |
1273 |
|
if (f == null || (b = o.toCompletableFuture()) == null) |
1274 |
|
throw new NullPointerException(); |
1275 |
|
CompletableFuture<Void> d = newIncompleteFuture(); |
1276 |
< |
if (e != null || !d.biAccept(this, b, f, null)) { |
1277 |
< |
BiAccept<T,U> c = new BiAccept<T,U>(e, d, this, b, f); |
1278 |
< |
if (e != null && result != null && b.result != null) { |
1279 |
< |
try { |
1280 |
< |
e.execute(c); |
1281 |
< |
} catch (Throwable ex) { |
1282 |
< |
d.completeThrowable(ex); |
1283 |
< |
} |
1284 |
< |
} |
1311 |
< |
else { |
1312 |
< |
bipush(b, c); |
1276 |
> |
if ((r = result) == null || (s = b.result) == null) |
1277 |
> |
bipush(b, new BiAccept<T,U>(e, d, this, b, f)); |
1278 |
> |
else if (e == null) |
1279 |
> |
d.biAccept(r, s, f, null); |
1280 |
> |
else |
1281 |
> |
try { |
1282 |
> |
e.execute(new BiAccept<T,U>(null, d, this, b, f)); |
1283 |
> |
} catch (Throwable ex) { |
1284 |
> |
d.result = encodeThrowable(ex); |
1285 |
|
} |
1314 |
– |
} |
1286 |
|
return d; |
1287 |
|
} |
1288 |
|
|
1299 |
|
CompletableFuture<Void> d; |
1300 |
|
CompletableFuture<T> a; |
1301 |
|
CompletableFuture<U> b; |
1302 |
< |
if ((d = dep) == null || |
1303 |
< |
!d.biRun(a = src, b = snd, fn, mode > 0 ? null : this)) |
1302 |
> |
Object r, s; Runnable f; |
1303 |
> |
if ((d = dep) == null || (f = fn) == null |
1304 |
> |
|| (a = src) == null || (r = a.result) == null |
1305 |
> |
|| (b = snd) == null || (s = b.result) == null |
1306 |
> |
|| !d.biRun(r, s, f, mode > 0 ? null : this)) |
1307 |
|
return null; |
1308 |
|
dep = null; src = null; snd = null; fn = null; |
1309 |
|
return d.postFire(a, b, mode); |
1310 |
|
} |
1311 |
|
} |
1312 |
|
|
1313 |
< |
final boolean biRun(CompletableFuture<?> a, CompletableFuture<?> b, |
1314 |
< |
Runnable f, BiRun<?,?> c) { |
1341 |
< |
Object r, s; Throwable x; |
1342 |
< |
if (a == null || (r = a.result) == null || |
1343 |
< |
b == null || (s = b.result) == null || f == null) |
1344 |
< |
return false; |
1313 |
> |
final boolean biRun(Object r, Object s, Runnable f, BiRun<?,?> c) { |
1314 |
> |
Throwable x; Object z; |
1315 |
|
if (result == null) { |
1316 |
< |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) |
1317 |
< |
completeThrowable(x, r); |
1318 |
< |
else if (s instanceof AltResult && (x = ((AltResult)s).ex) != null) |
1319 |
< |
completeThrowable(x, s); |
1316 |
> |
if ((r instanceof AltResult |
1317 |
> |
&& (x = ((AltResult)(z = r)).ex) != null) || |
1318 |
> |
(s instanceof AltResult |
1319 |
> |
&& (x = ((AltResult)(z = s)).ex) != null)) |
1320 |
> |
completeThrowable(x, z); |
1321 |
|
else |
1322 |
|
try { |
1323 |
|
if (c != null && !c.claim()) |
1333 |
|
|
1334 |
|
private CompletableFuture<Void> biRunStage(Executor e, CompletionStage<?> o, |
1335 |
|
Runnable f) { |
1336 |
< |
CompletableFuture<?> b; |
1336 |
> |
CompletableFuture<?> b; Object r, s; |
1337 |
|
if (f == null || (b = o.toCompletableFuture()) == null) |
1338 |
|
throw new NullPointerException(); |
1339 |
|
CompletableFuture<Void> d = newIncompleteFuture(); |
1340 |
< |
if (e != null || !d.biRun(this, b, f, null)) { |
1341 |
< |
BiRun<T,?> c = new BiRun<>(e, d, this, b, f); |
1342 |
< |
if (e != null && result != null && b.result != null) { |
1343 |
< |
try { |
1344 |
< |
e.execute(c); |
1345 |
< |
} catch (Throwable ex) { |
1346 |
< |
d.completeThrowable(ex); |
1347 |
< |
} |
1348 |
< |
} |
1378 |
< |
else { |
1379 |
< |
bipush(b, c); |
1340 |
> |
if ((r = result) == null || (s = b.result) == null) |
1341 |
> |
bipush(b, new BiRun<>(e, d, this, b, f)); |
1342 |
> |
else if (e == null) |
1343 |
> |
d.biRun(r, s, f, null); |
1344 |
> |
else |
1345 |
> |
try { |
1346 |
> |
e.execute(new BiRun<>(null, d, this, b, f)); |
1347 |
> |
} catch (Throwable ex) { |
1348 |
> |
d.result = encodeThrowable(ex); |
1349 |
|
} |
1381 |
– |
} |
1350 |
|
return d; |
1351 |
|
} |
1352 |
|
|
1361 |
|
CompletableFuture<Void> d; |
1362 |
|
CompletableFuture<T> a; |
1363 |
|
CompletableFuture<U> b; |
1364 |
< |
if ((d = dep) == null || !d.biRelay(a = src, b = snd)) |
1364 |
> |
Object r, s, z; Throwable x; |
1365 |
> |
if ((d = dep) == null |
1366 |
> |
|| (a = src) == null || (r = a.result) == null |
1367 |
> |
|| (b = snd) == null || (s = b.result) == null) |
1368 |
|
return null; |
1369 |
+ |
if (d.result == null) { |
1370 |
+ |
if ((r instanceof AltResult |
1371 |
+ |
&& (x = ((AltResult)(z = r)).ex) != null) || |
1372 |
+ |
(s instanceof AltResult |
1373 |
+ |
&& (x = ((AltResult)(z = s)).ex) != null)) |
1374 |
+ |
d.completeThrowable(x, z); |
1375 |
+ |
else |
1376 |
+ |
d.completeNull(); |
1377 |
+ |
} |
1378 |
|
src = null; snd = null; dep = null; |
1379 |
|
return d.postFire(a, b, mode); |
1380 |
|
} |
1381 |
|
} |
1382 |
|
|
1403 |
– |
boolean biRelay(CompletableFuture<?> a, CompletableFuture<?> b) { |
1404 |
– |
Object r, s; Throwable x; |
1405 |
– |
if (a == null || (r = a.result) == null || |
1406 |
– |
b == null || (s = b.result) == null) |
1407 |
– |
return false; |
1408 |
– |
if (result == null) { |
1409 |
– |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) |
1410 |
– |
completeThrowable(x, r); |
1411 |
– |
else if (s instanceof AltResult && (x = ((AltResult)s).ex) != null) |
1412 |
– |
completeThrowable(x, s); |
1413 |
– |
else |
1414 |
– |
completeNull(); |
1415 |
– |
} |
1416 |
– |
return true; |
1417 |
– |
} |
1418 |
– |
|
1383 |
|
/** Recursively constructs a tree of completions. */ |
1384 |
|
static CompletableFuture<Void> andTree(CompletableFuture<?>[] cfs, |
1385 |
|
int lo, int hi) { |
1387 |
|
if (lo > hi) // empty |
1388 |
|
d.result = NIL; |
1389 |
|
else { |
1390 |
< |
CompletableFuture<?> a, b; |
1390 |
> |
CompletableFuture<?> a, b; Object r, s, z; Throwable x; |
1391 |
|
int mid = (lo + hi) >>> 1; |
1392 |
|
if ((a = (lo == mid ? cfs[lo] : |
1393 |
|
andTree(cfs, lo, mid))) == null || |
1394 |
|
(b = (lo == hi ? a : (hi == mid+1) ? cfs[hi] : |
1395 |
|
andTree(cfs, mid+1, hi))) == null) |
1396 |
|
throw new NullPointerException(); |
1397 |
< |
if (!d.biRelay(a, b)) |
1397 |
> |
if ((r = a.result) == null || (s = b.result) == null) |
1398 |
|
a.bipush(b, new BiRelay<>(d, a, b)); |
1399 |
+ |
else if ((r instanceof AltResult |
1400 |
+ |
&& (x = ((AltResult)(z = r)).ex) != null) || |
1401 |
+ |
(s instanceof AltResult |
1402 |
+ |
&& (x = ((AltResult)(z = s)).ex) != null)) |
1403 |
+ |
d.result = encodeThrowable(x, z); |
1404 |
+ |
else |
1405 |
+ |
d.result = NIL; |
1406 |
|
} |
1407 |
|
return d; |
1408 |
|
} |
1442 |
|
CompletableFuture<T> a; |
1443 |
|
CompletableFuture<U> b; |
1444 |
|
Object r; Throwable x; Function<? super T,? extends V> f; |
1445 |
< |
if ((a = src) == null |
1446 |
< |
|| (b = snd) == null |
1447 |
< |
|| ((r = a.result) == null && (r = b.result) == null) |
1477 |
< |
|| (d = dep) == null |
1478 |
< |
|| (f = fn) == null) |
1445 |
> |
if ((d = dep) == null || (f = fn) == null |
1446 |
> |
|| (a = src) == null || (b = snd) == null |
1447 |
> |
|| ((r = a.result) == null && (r = b.result) == null)) |
1448 |
|
return null; |
1449 |
|
tryComplete: if (d.result == null) { |
1450 |
|
try { |
1498 |
|
CompletableFuture<T> a; |
1499 |
|
CompletableFuture<U> b; |
1500 |
|
Object r; Throwable x; Consumer<? super T> f; |
1501 |
< |
if ((a = src) == null |
1502 |
< |
|| (b = snd) == null |
1503 |
< |
|| ((r = a.result) == null && (r = b.result) == null) |
1535 |
< |
|| (d = dep) == null |
1536 |
< |
|| (f = fn) == null) |
1501 |
> |
if ((d = dep) == null || (f = fn) == null |
1502 |
> |
|| (a = src) == null || (b = snd) == null |
1503 |
> |
|| ((r = a.result) == null && (r = b.result) == null)) |
1504 |
|
return null; |
1505 |
|
tryComplete: if (d.result == null) { |
1506 |
|
try { |
1555 |
|
CompletableFuture<T> a; |
1556 |
|
CompletableFuture<U> b; |
1557 |
|
Object r; Throwable x; Runnable f; |
1558 |
< |
if ((a = src) == null |
1559 |
< |
|| (b = snd) == null |
1560 |
< |
|| ((r = a.result) == null && (r = b.result) == null) |
1594 |
< |
|| (d = dep) == null |
1595 |
< |
|| (f = fn) == null) |
1558 |
> |
if ((d = dep) == null || (f = fn) == null |
1559 |
> |
|| (a = src) == null || (b = snd) == null |
1560 |
> |
|| ((r = a.result) == null && (r = b.result) == null)) |
1561 |
|
return null; |
1562 |
|
if (d.result == null) { |
1563 |
|
try { |
1605 |
|
CompletableFuture<Object> d; |
1606 |
|
CompletableFuture<T> a; |
1607 |
|
CompletableFuture<U> b; |
1608 |
< |
if ((d = dep) == null || !d.orRelay(a = src, b = snd)) |
1608 |
> |
Object r; |
1609 |
> |
if ((d = dep) == null |
1610 |
> |
|| (a = src) == null || (b = snd) == null |
1611 |
> |
|| ((r = a.result) == null && (r = b.result) == null)) |
1612 |
|
return null; |
1613 |
+ |
d.completeRelay(r); |
1614 |
|
src = null; snd = null; dep = null; |
1615 |
|
return d.postFire(a, b, mode); |
1616 |
|
} |
1617 |
|
} |
1618 |
|
|
1650 |
– |
final boolean orRelay(CompletableFuture<?> a, CompletableFuture<?> b) { |
1651 |
– |
Object r; |
1652 |
– |
if (a == null || b == null || |
1653 |
– |
((r = a.result) == null && (r = b.result) == null)) |
1654 |
– |
return false; |
1655 |
– |
if (result == null) |
1656 |
– |
completeRelay(r); |
1657 |
– |
return true; |
1658 |
– |
} |
1659 |
– |
|
1619 |
|
/** Recursively constructs a tree of completions. */ |
1620 |
|
static CompletableFuture<Object> orTree(CompletableFuture<?>[] cfs, |
1621 |
|
int lo, int hi) { |
1622 |
|
CompletableFuture<Object> d = new CompletableFuture<Object>(); |
1623 |
|
if (lo <= hi) { |
1624 |
< |
CompletableFuture<?> a, b; |
1624 |
> |
CompletableFuture<?> a, b; Object r; |
1625 |
|
int mid = (lo + hi) >>> 1; |
1626 |
|
if ((a = (lo == mid ? cfs[lo] : |
1627 |
|
orTree(cfs, lo, mid))) == null || |
1628 |
|
(b = (lo == hi ? a : (hi == mid+1) ? cfs[hi] : |
1629 |
|
orTree(cfs, mid+1, hi))) == null) |
1630 |
|
throw new NullPointerException(); |
1631 |
< |
if (!d.orRelay(a, b)) |
1631 |
> |
if ((r = a.result) != null && (r = b.result) != null) |
1632 |
> |
d.result = encodeRelay(r); |
1633 |
> |
else |
1634 |
|
a.orpush(b, new OrRelay<>(d, a, b)); |
1635 |
|
} |
1636 |
|
return d; |