192 |
|
return UNSAFE.compareAndSwapObject(this, RESULT, null, r); |
193 |
|
} |
194 |
|
|
195 |
+ |
final boolean completeValue(T t) { |
196 |
+ |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
197 |
+ |
(t == null) ? NIL : t); |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
final boolean completeNil() { |
201 |
+ |
return UNSAFE.compareAndSwapObject(this, RESULT, null, NIL); |
202 |
+ |
} |
203 |
+ |
|
204 |
+ |
final boolean completeThrowable(Throwable x) { |
205 |
+ |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
206 |
+ |
encodeThrowable(x)); |
207 |
+ |
} |
208 |
+ |
|
209 |
+ |
final boolean completeRelay(Object r) { |
210 |
+ |
return UNSAFE.compareAndSwapObject(this, RESULT, null, encodeRelay(r)); |
211 |
+ |
} |
212 |
+ |
|
213 |
|
final boolean casStack(Completion cmp, Completion val) { |
214 |
|
return UNSAFE.compareAndSwapObject(this, STACK, cmp, val); |
215 |
|
} |
237 |
|
* is non-null, encodes as AltResult. Otherwise uses the given |
238 |
|
* value, boxed as NIL if null. |
239 |
|
*/ |
240 |
< |
static Object encodeOutcome(Object v, Throwable x) { |
241 |
< |
return (x == null) ? (v == null) ? NIL : v : encodeThrowable(x); |
240 |
> |
Object encodeOutcome(T t, Throwable x) { |
241 |
> |
return (x == null) ? (t == null) ? NIL : t : encodeThrowable(x); |
242 |
|
} |
243 |
|
|
244 |
|
/** |
305 |
|
public static interface AsynchronousCompletionTask { |
306 |
|
} |
307 |
|
|
308 |
+ |
private static final boolean useCommonPool = |
309 |
+ |
(ForkJoinPool.getCommonPoolParallelism() > 1); |
310 |
+ |
|
311 |
|
/** |
312 |
|
* Default executor -- ForkJoinPool.commonPool() unless it cannot |
313 |
|
* support parallelism. |
314 |
|
*/ |
315 |
< |
static final Executor asyncPool = |
295 |
< |
(ForkJoinPool.getCommonPoolParallelism() > 1) ? |
315 |
> |
private static final Executor asyncPool = useCommonPool ? |
316 |
|
ForkJoinPool.commonPool() : new ThreadPerTaskExecutor(); |
317 |
|
|
318 |
|
/** Fallback if ForkJoinPool.commonPool() cannot support parallelism */ |
325 |
|
* commonPool to asyncPool in case parallelism disabled. |
326 |
|
*/ |
327 |
|
static Executor screenExecutor(Executor e) { |
328 |
+ |
if (!useCommonPool && e == ForkJoinPool.commonPool()) |
329 |
+ |
return asyncPool; |
330 |
|
if (e == null) throw new NullPointerException(); |
331 |
< |
return (e == ForkJoinPool.commonPool()) ? asyncPool : e; |
331 |
> |
return e; |
332 |
|
} |
333 |
|
|
334 |
|
// Modes for Completion.exec. Signedness matters. |
495 |
|
final <S> boolean uniApply(CompletableFuture<S> a, |
496 |
|
Function<? super S,? extends T> f, |
497 |
|
UniApply<S,T> c) { |
498 |
< |
Object r; T t; Throwable x; |
498 |
> |
Object r; Throwable x; |
499 |
|
if (a == null || (r = a.result) == null || f == null) |
500 |
|
return false; |
501 |
|
if (result == null) { |
502 |
< |
try { |
503 |
< |
if (r instanceof AltResult) { |
504 |
< |
x = ((AltResult)r).ex; |
505 |
< |
r = null; |
506 |
< |
} |
507 |
< |
else |
508 |
< |
x = null; |
487 |
< |
if (x != null) |
488 |
< |
t = null; |
489 |
< |
else if (c != null && !c.claim()) |
502 |
> |
exceptionalCompletion: try { |
503 |
> |
if (r instanceof AltResult) |
504 |
> |
if ((x = ((AltResult)r).ex) != null) |
505 |
> |
break exceptionalCompletion; |
506 |
> |
else |
507 |
> |
r = null; |
508 |
> |
if (c != null && !c.claim()) |
509 |
|
return false; |
510 |
< |
else { |
511 |
< |
@SuppressWarnings("unchecked") S s = (S) r; |
512 |
< |
t = f.apply(s); |
494 |
< |
} |
510 |
> |
@SuppressWarnings("unchecked") S s = (S) r; |
511 |
> |
completeValue(f.apply(s)); |
512 |
> |
return true; |
513 |
|
} catch (Throwable ex) { |
514 |
|
x = ex; |
497 |
– |
t = null; |
515 |
|
} |
516 |
< |
internalComplete(encodeOutcome(t, x)); |
516 |
> |
completeThrowable(x); |
517 |
|
} |
518 |
|
return true; |
519 |
|
} |
553 |
|
if (a == null || (r = a.result) == null || f == null) |
554 |
|
return false; |
555 |
|
if (result == null) { |
556 |
< |
try { |
557 |
< |
if (r instanceof AltResult) { |
558 |
< |
x = ((AltResult)r).ex; |
559 |
< |
r = null; |
560 |
< |
} |
561 |
< |
else |
562 |
< |
x = null; |
563 |
< |
if (x == null) { |
564 |
< |
if (c != null && !c.claim()) |
565 |
< |
return false; |
566 |
< |
else { |
567 |
< |
@SuppressWarnings("unchecked") S s = (S) r; |
551 |
< |
f.accept(s); |
552 |
< |
} |
553 |
< |
} |
556 |
> |
exceptionalCompletion: try { |
557 |
> |
if (r instanceof AltResult) |
558 |
> |
if ((x = ((AltResult)r).ex) != null) |
559 |
> |
break exceptionalCompletion; |
560 |
> |
else |
561 |
> |
r = null; |
562 |
> |
if (c != null && !c.claim()) |
563 |
> |
return false; |
564 |
> |
@SuppressWarnings("unchecked") S s = (S) r; |
565 |
> |
f.accept(s); |
566 |
> |
completeNil(); |
567 |
> |
return true; |
568 |
|
} catch (Throwable ex) { |
569 |
|
x = ex; |
570 |
|
} |
571 |
< |
internalComplete(encodeOutcome(null, x)); |
571 |
> |
completeThrowable(x); |
572 |
|
} |
573 |
|
return true; |
574 |
|
} |
607 |
|
if (a == null || (r = a.result) == null || f == null) |
608 |
|
return false; |
609 |
|
if (result == null) { |
610 |
< |
try { |
611 |
< |
if (r instanceof AltResult) |
612 |
< |
x = ((AltResult)r).ex; |
613 |
< |
else |
614 |
< |
x = null; |
615 |
< |
if (x == null) { |
616 |
< |
if (c != null && !c.claim()) |
617 |
< |
return false; |
604 |
< |
else |
605 |
< |
f.run(); |
606 |
< |
} |
610 |
> |
exceptionalCompletion: try { |
611 |
> |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) |
612 |
> |
break exceptionalCompletion; |
613 |
> |
if (c != null && !c.claim()) |
614 |
> |
return false; |
615 |
> |
f.run(); |
616 |
> |
completeNil(); |
617 |
> |
return true; |
618 |
|
} catch (Throwable ex) { |
619 |
|
x = ex; |
620 |
|
} |
621 |
< |
internalComplete(encodeOutcome(null, x)); |
621 |
> |
completeThrowable(x); |
622 |
|
} |
623 |
|
return true; |
624 |
|
} |
655 |
|
final boolean uniWhenComplete(CompletableFuture<T> a, |
656 |
|
BiConsumer<? super T,? super Throwable> f, |
657 |
|
UniWhenComplete<T> c) { |
658 |
< |
Object r; |
658 |
> |
Object r; T t; Throwable x = null; |
659 |
|
if (a == null || (r = a.result) == null || f == null) |
660 |
|
return false; |
661 |
|
if (result == null) { |
651 |
– |
Throwable x = null, y = null; |
662 |
|
try { |
663 |
+ |
if (c != null && !c.claim()) |
664 |
+ |
return false; |
665 |
|
if (r instanceof AltResult) { |
666 |
|
x = ((AltResult)r).ex; |
667 |
< |
r = null; |
667 |
> |
t = null; |
668 |
> |
} else { |
669 |
> |
@SuppressWarnings("unchecked") T tr = (T) r; |
670 |
> |
t = tr; |
671 |
|
} |
672 |
< |
if (c != null && !c.claim()) |
673 |
< |
return false; |
674 |
< |
else { |
675 |
< |
@SuppressWarnings("unchecked") T t = (T) r; |
661 |
< |
f.accept(t, x); |
672 |
> |
f.accept(t, x); |
673 |
> |
if (x == null) { |
674 |
> |
internalComplete(r); |
675 |
> |
return true; |
676 |
|
} |
677 |
|
} catch (Throwable ex) { |
678 |
< |
y = ex; |
678 |
> |
if (x == null) |
679 |
> |
x = ex; |
680 |
|
} |
681 |
< |
internalComplete(encodeOutcome(r, x != null ? x : y)); |
681 |
> |
completeThrowable(x); |
682 |
|
} |
683 |
|
return true; |
684 |
|
} |
716 |
|
final <S> boolean uniHandle(CompletableFuture<S> a, |
717 |
|
BiFunction<? super S, Throwable, ? extends T> f, |
718 |
|
UniHandle<S,T> c) { |
719 |
< |
Object r; T t; Throwable x, y; |
719 |
> |
Object r; S s; Throwable x; |
720 |
|
if (a == null || (r = a.result) == null || f == null) |
721 |
|
return false; |
722 |
|
if (result == null) { |
723 |
|
try { |
724 |
+ |
if (c != null && !c.claim()) |
725 |
+ |
return false; |
726 |
|
if (r instanceof AltResult) { |
727 |
|
x = ((AltResult)r).ex; |
728 |
< |
r = null; |
729 |
< |
} |
713 |
< |
else |
728 |
> |
s = null; |
729 |
> |
} else { |
730 |
|
x = null; |
731 |
< |
if (c != null && !c.claim()) |
732 |
< |
return false; |
717 |
< |
else { |
718 |
< |
@SuppressWarnings("unchecked") S s = (S) r; |
719 |
< |
t = f.apply(s, x); |
720 |
< |
y = null; |
731 |
> |
@SuppressWarnings("unchecked") S ss = (S) r; |
732 |
> |
s = ss; |
733 |
|
} |
734 |
+ |
completeValue(f.apply(s, x)); |
735 |
|
} catch (Throwable ex) { |
736 |
< |
y = ex; |
724 |
< |
t = null; |
736 |
> |
completeThrowable(ex); |
737 |
|
} |
726 |
– |
internalComplete(encodeOutcome(t, y)); |
738 |
|
} |
739 |
|
return true; |
740 |
|
} |
770 |
|
final boolean uniExceptionally(CompletableFuture<T> a, |
771 |
|
Function<? super Throwable, ? extends T> f, |
772 |
|
UniExceptionally<T> c) { |
773 |
< |
Object r; T t; Throwable x, y; |
773 |
> |
Object r; Throwable x; |
774 |
|
if (a == null || (r = a.result) == null || f == null) |
775 |
|
return false; |
765 |
– |
if (r instanceof AltResult) |
766 |
– |
x = ((AltResult)r).ex; |
767 |
– |
else |
768 |
– |
x = null; |
776 |
|
if (result == null) { |
777 |
|
try { |
778 |
< |
if (c != null && !c.claim()) |
779 |
< |
return false; |
780 |
< |
else if (x == null) { |
781 |
< |
@SuppressWarnings("unchecked") T tr = (T) r; |
782 |
< |
t = tr; |
783 |
< |
y = null; |
777 |
< |
} |
778 |
< |
else { |
779 |
< |
t = f.apply(x); |
780 |
< |
y = null; |
781 |
< |
} |
778 |
> |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) { |
779 |
> |
if (c != null && !c.claim()) |
780 |
> |
return false; |
781 |
> |
completeValue(f.apply(x)); |
782 |
> |
} else |
783 |
> |
internalComplete(r); |
784 |
|
} catch (Throwable ex) { |
785 |
< |
y = ex; |
784 |
< |
t = null; |
785 |
> |
completeThrowable(ex); |
786 |
|
} |
786 |
– |
internalComplete(encodeOutcome(t, y)); |
787 |
|
} |
788 |
|
return true; |
789 |
|
} |
818 |
|
Object r; |
819 |
|
if (a == null || (r = a.result) == null) |
820 |
|
return false; |
821 |
– |
Object s = encodeRelay(r); |
821 |
|
if (result == null) // no need to claim |
822 |
< |
internalComplete(s); |
822 |
> |
completeRelay(r); |
823 |
|
return true; |
824 |
|
} |
825 |
|
|
849 |
|
if (a == null || (r = a.result) == null || f == null) |
850 |
|
return false; |
851 |
|
if (result == null) { |
852 |
< |
try { |
853 |
< |
if (r instanceof AltResult) { |
854 |
< |
x = ((AltResult)r).ex; |
855 |
< |
r = null; |
856 |
< |
} |
857 |
< |
else |
858 |
< |
x = null; |
859 |
< |
if (x == null) { |
860 |
< |
if (c != null && !c.claim()) |
852 |
> |
exceptionalCompletion: try { |
853 |
> |
if (r instanceof AltResult) |
854 |
> |
if ((x = ((AltResult)r).ex) != null) |
855 |
> |
break exceptionalCompletion; |
856 |
> |
else |
857 |
> |
r = null; |
858 |
> |
if (c != null && !c.claim()) |
859 |
> |
return false; |
860 |
> |
@SuppressWarnings("unchecked") S s = (S) r; |
861 |
> |
CompletableFuture<T> g = f.apply(s).toCompletableFuture(); |
862 |
> |
if (g.result == null || !uniRelay(g)) { |
863 |
> |
UniRelay<T> copy = new UniRelay<T>(this, g); |
864 |
> |
g.push(copy); |
865 |
> |
copy.tryFire(SYNC); |
866 |
> |
if (result == null) |
867 |
|
return false; |
863 |
– |
else { |
864 |
– |
@SuppressWarnings("unchecked") S s = (S) r; |
865 |
– |
CompletableFuture<T> g = |
866 |
– |
f.apply(s).toCompletableFuture(); |
867 |
– |
if (g.result == null || !uniRelay(g)) { |
868 |
– |
UniRelay<T> copy = new UniRelay<T>(this, g); |
869 |
– |
g.push(copy); |
870 |
– |
copy.tryFire(SYNC); |
871 |
– |
if (result == null) |
872 |
– |
return false; |
873 |
– |
} |
874 |
– |
} |
868 |
|
} |
869 |
+ |
return true; |
870 |
|
} catch (Throwable ex) { |
871 |
|
x = ex; |
872 |
|
} |
873 |
< |
if (x != null) |
880 |
< |
internalComplete(encodeOutcome(null, x)); |
873 |
> |
completeThrowable(x); |
874 |
|
} |
875 |
|
return true; |
876 |
|
} |
879 |
|
Executor e, Function<? super T, ? extends CompletionStage<V>> f) { |
880 |
|
if (f == null) throw new NullPointerException(); |
881 |
|
Object r; Throwable x; |
882 |
< |
if (e == null && (r = result) != null) { |
883 |
< |
try { // try to return function result |
884 |
< |
if (r instanceof AltResult) { |
885 |
< |
x = ((AltResult)r).ex; |
886 |
< |
r = null; |
887 |
< |
} |
888 |
< |
else |
889 |
< |
x = null; |
890 |
< |
if (x == null) { |
891 |
< |
@SuppressWarnings("unchecked") T t = (T) r; |
892 |
< |
return f.apply(t).toCompletableFuture(); |
900 |
< |
} |
882 |
> |
if (e != null || (r = result) == null) |
883 |
> |
x = null; |
884 |
> |
else { // try to return function result directly |
885 |
> |
exceptionalCompletion: try { |
886 |
> |
if (r instanceof AltResult) |
887 |
> |
if ((x = ((AltResult)r).ex) != null) |
888 |
> |
break exceptionalCompletion; |
889 |
> |
else |
890 |
> |
r = null; |
891 |
> |
@SuppressWarnings("unchecked") T t = (T) r; |
892 |
> |
return f.apply(t).toCompletableFuture(); |
893 |
|
} catch (Throwable ex) { |
894 |
|
x = ex; |
895 |
|
} |
896 |
|
} |
905 |
– |
else |
906 |
– |
x = null; |
897 |
|
CompletableFuture<V> d = new CompletableFuture<V>(); |
898 |
< |
if (x == null) { |
898 |
> |
if (x != null) { |
899 |
> |
d.result = encodeThrowable(x); |
900 |
> |
} else { |
901 |
|
UniCompose<T,V> c = new UniCompose<T,V>(e, d, this, f); |
902 |
|
push(c); |
903 |
|
c.tryFire(SYNC); |
904 |
|
} |
913 |
– |
else |
914 |
– |
d.result = encodeOutcome(null, x); |
905 |
|
return d; |
906 |
|
} |
907 |
|
|
985 |
|
CompletableFuture<S> b, |
986 |
|
BiFunction<? super R,? super S,? extends T> f, |
987 |
|
BiApply<R,S,T> c) { |
988 |
< |
Object r, s; T t; Throwable x; |
988 |
> |
Object r, s; Throwable x; |
989 |
|
if (a == null || (r = a.result) == null || |
990 |
|
b == null || (s = b.result) == null || f == null) |
991 |
|
return false; |
992 |
|
if (result == null) { |
993 |
< |
try { |
994 |
< |
if (r instanceof AltResult) { |
995 |
< |
x = ((AltResult)r).ex; |
996 |
< |
r = null; |
997 |
< |
} |
998 |
< |
else |
999 |
< |
x = null; |
1000 |
< |
if (x == null && (s instanceof AltResult)) { |
1001 |
< |
x = ((AltResult)s).ex; |
1002 |
< |
s = null; |
1003 |
< |
} |
1004 |
< |
if (x != null) |
1015 |
< |
t = null; |
1016 |
< |
else if (c != null && !c.claim()) |
993 |
> |
exceptionalCompletion: try { |
994 |
> |
if (r instanceof AltResult) |
995 |
> |
if ((x = ((AltResult)r).ex) != null) |
996 |
> |
break exceptionalCompletion; |
997 |
> |
else |
998 |
> |
r = null; |
999 |
> |
if (s instanceof AltResult) |
1000 |
> |
if ((x = ((AltResult)s).ex) != null) |
1001 |
> |
break exceptionalCompletion; |
1002 |
> |
else |
1003 |
> |
s = null; |
1004 |
> |
if (c != null && !c.claim()) |
1005 |
|
return false; |
1006 |
< |
else { |
1007 |
< |
@SuppressWarnings("unchecked") R rr = (R) r; |
1008 |
< |
@SuppressWarnings("unchecked") S ss = (S) s; |
1009 |
< |
t = f.apply(rr, ss); |
1022 |
< |
} |
1006 |
> |
@SuppressWarnings("unchecked") R rr = (R) r; |
1007 |
> |
@SuppressWarnings("unchecked") S ss = (S) s; |
1008 |
> |
completeValue(f.apply(rr, ss)); |
1009 |
> |
return true; |
1010 |
|
} catch (Throwable ex) { |
1011 |
|
x = ex; |
1025 |
– |
t = null; |
1012 |
|
} |
1013 |
< |
internalComplete(encodeOutcome(t, x)); |
1013 |
> |
completeThrowable(x); |
1014 |
|
} |
1015 |
|
return true; |
1016 |
|
} |
1059 |
|
b == null || (s = b.result) == null || f == null) |
1060 |
|
return false; |
1061 |
|
if (result == null) { |
1062 |
< |
try { |
1063 |
< |
if (r instanceof AltResult) { |
1064 |
< |
x = ((AltResult)r).ex; |
1065 |
< |
r = null; |
1066 |
< |
} |
1067 |
< |
else |
1068 |
< |
x = null; |
1069 |
< |
if (x == null && (s instanceof AltResult)) { |
1070 |
< |
x = ((AltResult)s).ex; |
1071 |
< |
s = null; |
1072 |
< |
} |
1073 |
< |
if (x == null) { |
1074 |
< |
if (c != null && !c.claim()) |
1075 |
< |
return false; |
1076 |
< |
else { |
1077 |
< |
@SuppressWarnings("unchecked") R rr = (R) r; |
1078 |
< |
@SuppressWarnings("unchecked") S ss = (S) s; |
1079 |
< |
f.accept(rr, ss); |
1094 |
< |
} |
1095 |
< |
} |
1062 |
> |
exceptionalCompletion: try { |
1063 |
> |
if (r instanceof AltResult) |
1064 |
> |
if ((x = ((AltResult)r).ex) != null) |
1065 |
> |
break exceptionalCompletion; |
1066 |
> |
else |
1067 |
> |
r = null; |
1068 |
> |
if (s instanceof AltResult) |
1069 |
> |
if ((x = ((AltResult)s).ex) != null) |
1070 |
> |
break exceptionalCompletion; |
1071 |
> |
else |
1072 |
> |
s = null; |
1073 |
> |
if (c != null && !c.claim()) |
1074 |
> |
return false; |
1075 |
> |
@SuppressWarnings("unchecked") R rr = (R) r; |
1076 |
> |
@SuppressWarnings("unchecked") S ss = (S) s; |
1077 |
> |
f.accept(rr, ss); |
1078 |
> |
completeNil(); |
1079 |
> |
return true; |
1080 |
|
} catch (Throwable ex) { |
1081 |
|
x = ex; |
1082 |
|
} |
1083 |
< |
internalComplete(encodeOutcome(null, x)); |
1083 |
> |
completeThrowable(x); |
1084 |
|
} |
1085 |
|
return true; |
1086 |
|
} |
1128 |
|
b == null || (s = b.result) == null || f == null) |
1129 |
|
return false; |
1130 |
|
if (result == null) { |
1131 |
< |
try { |
1132 |
< |
if (r instanceof AltResult) |
1133 |
< |
x = ((AltResult)r).ex; |
1134 |
< |
else |
1135 |
< |
x = null; |
1136 |
< |
if (x == null && (s instanceof AltResult)) |
1137 |
< |
x = ((AltResult)s).ex; |
1138 |
< |
if (x == null) { |
1139 |
< |
if (c != null && !c.claim()) |
1156 |
< |
return false; |
1157 |
< |
else |
1158 |
< |
f.run(); |
1159 |
< |
} |
1131 |
> |
exceptionalCompletion: try { |
1132 |
> |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null || |
1133 |
> |
s instanceof AltResult && (x = ((AltResult)s).ex) != null) |
1134 |
> |
break exceptionalCompletion; |
1135 |
> |
if (c != null && !c.claim()) |
1136 |
> |
return false; |
1137 |
> |
f.run(); |
1138 |
> |
completeNil(); |
1139 |
> |
return true; |
1140 |
|
} catch (Throwable ex) { |
1141 |
|
x = ex; |
1142 |
|
} |
1143 |
< |
internalComplete(encodeOutcome(null, x)); |
1143 |
> |
completeThrowable(x); |
1144 |
|
} |
1145 |
|
return true; |
1146 |
|
} |
1183 |
|
b == null || (s = b.result) == null) |
1184 |
|
return false; |
1185 |
|
if (result == null) { |
1186 |
< |
if (r instanceof AltResult) |
1187 |
< |
x = ((AltResult)r).ex; |
1186 |
> |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null || |
1187 |
> |
s instanceof AltResult && (x = ((AltResult)s).ex) != null) |
1188 |
> |
completeThrowable(x); |
1189 |
|
else |
1190 |
< |
x = null; |
1210 |
< |
if (x == null && (s instanceof AltResult)) |
1211 |
< |
x = ((AltResult)s).ex; |
1212 |
< |
internalComplete(encodeOutcome(null, x)); |
1190 |
> |
completeNil(); |
1191 |
|
} |
1192 |
|
return true; |
1193 |
|
} |
1260 |
|
CompletableFuture<S> b, |
1261 |
|
Function<? super R, ? extends T> f, |
1262 |
|
OrApply<R,S,T> c) { |
1263 |
< |
Object r; T t; Throwable x; |
1263 |
> |
Object r; Throwable x; |
1264 |
|
if (a == null || b == null || |
1265 |
|
((r = a.result) == null && (r = b.result) == null) || f == null) |
1266 |
|
return false; |
1267 |
|
if (result == null) { |
1268 |
< |
try { |
1269 |
< |
if (r instanceof AltResult) { |
1292 |
< |
x = ((AltResult)r).ex; |
1293 |
< |
r = null; |
1294 |
< |
} |
1295 |
< |
else |
1296 |
< |
x = null; |
1297 |
< |
if (x != null) |
1298 |
< |
t = null; |
1299 |
< |
else if (c != null && !c.claim()) |
1268 |
> |
exceptionalCompletion: try { |
1269 |
> |
if (c != null && !c.claim()) |
1270 |
|
return false; |
1271 |
< |
else { |
1272 |
< |
@SuppressWarnings("unchecked") R rr = (R) r; |
1273 |
< |
t = f.apply(rr); |
1274 |
< |
} |
1271 |
> |
if (r instanceof AltResult) |
1272 |
> |
if ((x = ((AltResult)r).ex) != null) |
1273 |
> |
break exceptionalCompletion; |
1274 |
> |
else |
1275 |
> |
r = null; |
1276 |
> |
@SuppressWarnings("unchecked") R rr = (R) r; |
1277 |
> |
completeValue(f.apply(rr)); |
1278 |
> |
return true; |
1279 |
|
} catch (Throwable ex) { |
1280 |
|
x = ex; |
1307 |
– |
t = null; |
1281 |
|
} |
1282 |
< |
internalComplete(encodeOutcome(t, x)); |
1282 |
> |
completeThrowable(x); |
1283 |
|
} |
1284 |
|
return true; |
1285 |
|
} |
1329 |
|
((r = a.result) == null && (r = b.result) == null) || f == null) |
1330 |
|
return false; |
1331 |
|
if (result == null) { |
1332 |
< |
try { |
1333 |
< |
if (r instanceof AltResult) { |
1334 |
< |
x = ((AltResult)r).ex; |
1335 |
< |
r = null; |
1336 |
< |
} |
1337 |
< |
else |
1338 |
< |
x = null; |
1339 |
< |
if (x == null) { |
1340 |
< |
if (c != null && !c.claim()) |
1341 |
< |
return false; |
1342 |
< |
else { |
1343 |
< |
@SuppressWarnings("unchecked") R rr = (R) r; |
1371 |
< |
f.accept(rr); |
1372 |
< |
} |
1373 |
< |
} |
1332 |
> |
exceptionalCompletion: try { |
1333 |
> |
if (c != null && !c.claim()) |
1334 |
> |
return false; |
1335 |
> |
if (r instanceof AltResult) |
1336 |
> |
if ((x = ((AltResult)r).ex) != null) |
1337 |
> |
break exceptionalCompletion; |
1338 |
> |
else |
1339 |
> |
r = null; |
1340 |
> |
@SuppressWarnings("unchecked") R rr = (R) r; |
1341 |
> |
f.accept(rr); |
1342 |
> |
completeNil(); |
1343 |
> |
return true; |
1344 |
|
} catch (Throwable ex) { |
1345 |
|
x = ex; |
1346 |
|
} |
1347 |
< |
internalComplete(encodeOutcome(null, x)); |
1347 |
> |
completeThrowable(x); |
1348 |
|
} |
1349 |
|
return true; |
1350 |
|
} |
1391 |
|
((r = a.result) == null && (r = b.result) == null) || f == null) |
1392 |
|
return false; |
1393 |
|
if (result == null) { |
1394 |
< |
try { |
1395 |
< |
if (r instanceof AltResult) |
1396 |
< |
x = ((AltResult)r).ex; |
1397 |
< |
else |
1398 |
< |
x = null; |
1399 |
< |
if (x == null) { |
1400 |
< |
if (c != null && !c.claim()) |
1401 |
< |
return false; |
1432 |
< |
else |
1433 |
< |
f.run(); |
1434 |
< |
} |
1394 |
> |
exceptionalCompletion: try { |
1395 |
> |
if (c != null && !c.claim()) |
1396 |
> |
return false; |
1397 |
> |
if (r instanceof AltResult && (x = ((AltResult)r).ex) != null) |
1398 |
> |
break exceptionalCompletion; |
1399 |
> |
f.run(); |
1400 |
> |
completeNil(); |
1401 |
> |
return true; |
1402 |
|
} catch (Throwable ex) { |
1403 |
|
x = ex; |
1404 |
|
} |
1405 |
< |
internalComplete(encodeOutcome(null, x)); |
1405 |
> |
completeThrowable(x); |
1406 |
|
} |
1407 |
|
return true; |
1408 |
|
} |
1443 |
|
if (a == null || b == null || |
1444 |
|
((r = a.result) == null && (r = b.result) == null)) |
1445 |
|
return false; |
1479 |
– |
Object s = encodeRelay(r); |
1446 |
|
if (result == null) |
1447 |
< |
internalComplete(s); |
1447 |
> |
completeRelay(r); |
1448 |
|
return true; |
1449 |
|
} |
1450 |
|
|
1483 |
|
if ((d = dep) != null && (f = fn) != null) { |
1484 |
|
dep = null; fn = null; |
1485 |
|
if (d.result == null) { |
1520 |
– |
T t; Throwable x; |
1486 |
|
try { |
1487 |
< |
t = f.get(); |
1523 |
< |
x = null; |
1487 |
> |
d.completeValue(f.get()); |
1488 |
|
} catch (Throwable ex) { |
1489 |
< |
x = ex; |
1526 |
< |
t = null; |
1489 |
> |
d.completeThrowable(ex); |
1490 |
|
} |
1528 |
– |
d.internalComplete(encodeOutcome(t, x)); |
1491 |
|
} |
1492 |
|
d.postComplete(); |
1493 |
|
} |
1516 |
|
if ((d = dep) != null && (f = fn) != null) { |
1517 |
|
dep = null; fn = null; |
1518 |
|
if (d.result == null) { |
1557 |
– |
Throwable x; |
1519 |
|
try { |
1520 |
|
f.run(); |
1521 |
< |
x = null; |
1521 |
> |
d.completeNil(); |
1522 |
|
} catch (Throwable ex) { |
1523 |
< |
x = ex; |
1523 |
> |
d.completeThrowable(ex); |
1524 |
|
} |
1564 |
– |
d.internalComplete(encodeOutcome(null, x)); |
1525 |
|
} |
1526 |
|
d.postComplete(); |
1527 |
|
} |
1847 |
|
* to transition to a completed state, else {@code false} |
1848 |
|
*/ |
1849 |
|
public boolean complete(T value) { |
1850 |
< |
boolean triggered = internalComplete(value == null ? NIL : value); |
1850 |
> |
boolean triggered = completeValue(value); |
1851 |
|
postComplete(); |
1852 |
|
return triggered; |
1853 |
|
} |