479 |
|
private static final long serialVersionUID = 5232453952276885070L; |
480 |
|
} |
481 |
|
|
482 |
< |
static final class AsyncBiApply<T,U,V> extends Async { |
482 |
> |
static final class AsyncCombine<T,U,V> extends Async { |
483 |
|
final T arg1; |
484 |
|
final U arg2; |
485 |
|
final BiFunction<? super T,? super U,? extends V> fn; |
486 |
|
final CompletableFuture<V> dst; |
487 |
< |
AsyncBiApply(T arg1, U arg2, |
487 |
> |
AsyncCombine(T arg1, U arg2, |
488 |
|
BiFunction<? super T,? super U,? extends V> fn, |
489 |
|
CompletableFuture<V> dst) { |
490 |
|
this.arg1 = arg1; this.arg2 = arg2; this.fn = fn; this.dst = dst; |
530 |
|
private static final long serialVersionUID = 5232453952276885070L; |
531 |
|
} |
532 |
|
|
533 |
< |
static final class AsyncBiAccept<T,U> extends Async { |
533 |
> |
static final class AsyncAcceptBoth<T,U> extends Async { |
534 |
|
final T arg1; |
535 |
|
final U arg2; |
536 |
|
final BiConsumer<? super T,? super U> fn; |
537 |
|
final CompletableFuture<Void> dst; |
538 |
< |
AsyncBiAccept(T arg1, U arg2, |
539 |
< |
BiConsumer<? super T,? super U> fn, |
540 |
< |
CompletableFuture<Void> dst) { |
538 |
> |
AsyncAcceptBoth(T arg1, U arg2, |
539 |
> |
BiConsumer<? super T,? super U> fn, |
540 |
> |
CompletableFuture<Void> dst) { |
541 |
|
this.arg1 = arg1; this.arg2 = arg2; this.fn = fn; this.dst = dst; |
542 |
|
} |
543 |
|
public final boolean exec() { |
615 |
|
abstract static class Completion extends AtomicInteger implements Runnable { |
616 |
|
} |
617 |
|
|
618 |
< |
static final class ApplyCompletion<T,U> extends Completion { |
618 |
> |
static final class ThenApply<T,U> extends Completion { |
619 |
|
final CompletableFuture<? extends T> src; |
620 |
|
final Function<? super T,? extends U> fn; |
621 |
|
final CompletableFuture<U> dst; |
622 |
|
final Executor executor; |
623 |
< |
ApplyCompletion(CompletableFuture<? extends T> src, |
624 |
< |
Function<? super T,? extends U> fn, |
625 |
< |
CompletableFuture<U> dst, Executor executor) { |
623 |
> |
ThenApply(CompletableFuture<? extends T> src, |
624 |
> |
Function<? super T,? extends U> fn, |
625 |
> |
CompletableFuture<U> dst, |
626 |
> |
Executor executor) { |
627 |
|
this.src = src; this.fn = fn; this.dst = dst; |
628 |
|
this.executor = executor; |
629 |
|
} |
665 |
|
private static final long serialVersionUID = 5232453952276885070L; |
666 |
|
} |
667 |
|
|
668 |
< |
static final class AcceptCompletion<T> extends Completion { |
668 |
> |
static final class ThenAccept<T> extends Completion { |
669 |
|
final CompletableFuture<? extends T> src; |
670 |
|
final Consumer<? super T> fn; |
671 |
|
final CompletableFuture<Void> dst; |
672 |
|
final Executor executor; |
673 |
< |
AcceptCompletion(CompletableFuture<? extends T> src, |
674 |
< |
Consumer<? super T> fn, |
675 |
< |
CompletableFuture<Void> dst, Executor executor) { |
673 |
> |
ThenAccept(CompletableFuture<? extends T> src, |
674 |
> |
Consumer<? super T> fn, |
675 |
> |
CompletableFuture<Void> dst, |
676 |
> |
Executor executor) { |
677 |
|
this.src = src; this.fn = fn; this.dst = dst; |
678 |
|
this.executor = executor; |
679 |
|
} |
714 |
|
private static final long serialVersionUID = 5232453952276885070L; |
715 |
|
} |
716 |
|
|
717 |
< |
static final class RunCompletion<T> extends Completion { |
717 |
> |
static final class ThenRun<T> extends Completion { |
718 |
|
final CompletableFuture<? extends T> src; |
719 |
|
final Runnable fn; |
720 |
|
final CompletableFuture<Void> dst; |
721 |
|
final Executor executor; |
722 |
< |
RunCompletion(CompletableFuture<? extends T> src, |
723 |
< |
Runnable fn, |
724 |
< |
CompletableFuture<Void> dst, |
725 |
< |
Executor executor) { |
722 |
> |
ThenRun(CompletableFuture<? extends T> src, |
723 |
> |
Runnable fn, |
724 |
> |
CompletableFuture<Void> dst, |
725 |
> |
Executor executor) { |
726 |
|
this.src = src; this.fn = fn; this.dst = dst; |
727 |
|
this.executor = executor; |
728 |
|
} |
758 |
|
private static final long serialVersionUID = 5232453952276885070L; |
759 |
|
} |
760 |
|
|
761 |
< |
static final class BiApplyCompletion<T,U,V> extends Completion { |
761 |
> |
static final class ThenCombine<T,U,V> extends Completion { |
762 |
|
final CompletableFuture<? extends T> src; |
763 |
|
final CompletableFuture<? extends U> snd; |
764 |
|
final BiFunction<? super T,? super U,? extends V> fn; |
765 |
|
final CompletableFuture<V> dst; |
766 |
|
final Executor executor; |
767 |
< |
BiApplyCompletion(CompletableFuture<? extends T> src, |
768 |
< |
CompletableFuture<? extends U> snd, |
769 |
< |
BiFunction<? super T,? super U,? extends V> fn, |
770 |
< |
CompletableFuture<V> dst, Executor executor) { |
767 |
> |
ThenCombine(CompletableFuture<? extends T> src, |
768 |
> |
CompletableFuture<? extends U> snd, |
769 |
> |
BiFunction<? super T,? super U,? extends V> fn, |
770 |
> |
CompletableFuture<V> dst, |
771 |
> |
Executor executor) { |
772 |
|
this.src = src; this.snd = snd; |
773 |
|
this.fn = fn; this.dst = dst; |
774 |
|
this.executor = executor; |
810 |
|
if (ex == null) { |
811 |
|
try { |
812 |
|
if (e != null) |
813 |
< |
e.execute(new AsyncBiApply<T,U,V>(t, u, fn, dst)); |
813 |
> |
e.execute(new AsyncCombine<T,U,V>(t, u, fn, dst)); |
814 |
|
else |
815 |
|
v = fn.apply(t, u); |
816 |
|
} catch (Throwable rex) { |
824 |
|
private static final long serialVersionUID = 5232453952276885070L; |
825 |
|
} |
826 |
|
|
827 |
< |
static final class BiAcceptCompletion<T,U> extends Completion { |
827 |
> |
static final class ThenAcceptBoth<T,U> extends Completion { |
828 |
|
final CompletableFuture<? extends T> src; |
829 |
|
final CompletableFuture<? extends U> snd; |
830 |
|
final BiConsumer<? super T,? super U> fn; |
831 |
|
final CompletableFuture<Void> dst; |
832 |
|
final Executor executor; |
833 |
< |
BiAcceptCompletion(CompletableFuture<? extends T> src, |
834 |
< |
CompletableFuture<? extends U> snd, |
835 |
< |
BiConsumer<? super T,? super U> fn, |
836 |
< |
CompletableFuture<Void> dst, Executor executor) { |
833 |
> |
ThenAcceptBoth(CompletableFuture<? extends T> src, |
834 |
> |
CompletableFuture<? extends U> snd, |
835 |
> |
BiConsumer<? super T,? super U> fn, |
836 |
> |
CompletableFuture<Void> dst, |
837 |
> |
Executor executor) { |
838 |
|
this.src = src; this.snd = snd; |
839 |
|
this.fn = fn; this.dst = dst; |
840 |
|
this.executor = executor; |
875 |
|
if (ex == null) { |
876 |
|
try { |
877 |
|
if (e != null) |
878 |
< |
e.execute(new AsyncBiAccept<T,U>(t, u, fn, dst)); |
878 |
> |
e.execute(new AsyncAcceptBoth<T,U>(t, u, fn, dst)); |
879 |
|
else |
880 |
|
fn.accept(t, u); |
881 |
|
} catch (Throwable rex) { |
889 |
|
private static final long serialVersionUID = 5232453952276885070L; |
890 |
|
} |
891 |
|
|
892 |
< |
static final class BiRunCompletion<T> extends Completion { |
892 |
> |
static final class RunAfterBoth<T> extends Completion { |
893 |
|
final CompletableFuture<? extends T> src; |
894 |
|
final CompletableFuture<?> snd; |
895 |
|
final Runnable fn; |
896 |
|
final CompletableFuture<Void> dst; |
897 |
|
final Executor executor; |
898 |
< |
BiRunCompletion(CompletableFuture<? extends T> src, |
899 |
< |
CompletableFuture<?> snd, |
900 |
< |
Runnable fn, |
901 |
< |
CompletableFuture<Void> dst, Executor executor) { |
898 |
> |
RunAfterBoth(CompletableFuture<? extends T> src, |
899 |
> |
CompletableFuture<?> snd, |
900 |
> |
Runnable fn, |
901 |
> |
CompletableFuture<Void> dst, |
902 |
> |
Executor executor) { |
903 |
|
this.src = src; this.snd = snd; |
904 |
|
this.fn = fn; this.dst = dst; |
905 |
|
this.executor = executor; |
973 |
|
private static final long serialVersionUID = 5232453952276885070L; |
974 |
|
} |
975 |
|
|
976 |
< |
static final class OrApplyCompletion<T,U> extends Completion { |
976 |
> |
static final class ApplyToEither<T,U> extends Completion { |
977 |
|
final CompletableFuture<? extends T> src; |
978 |
|
final CompletableFuture<? extends T> snd; |
979 |
|
final Function<? super T,? extends U> fn; |
980 |
|
final CompletableFuture<U> dst; |
981 |
|
final Executor executor; |
982 |
< |
OrApplyCompletion(CompletableFuture<? extends T> src, |
983 |
< |
CompletableFuture<? extends T> snd, |
984 |
< |
Function<? super T,? extends U> fn, |
985 |
< |
CompletableFuture<U> dst, Executor executor) { |
982 |
> |
ApplyToEither(CompletableFuture<? extends T> src, |
983 |
> |
CompletableFuture<? extends T> snd, |
984 |
> |
Function<? super T,? extends U> fn, |
985 |
> |
CompletableFuture<U> dst, |
986 |
> |
Executor executor) { |
987 |
|
this.src = src; this.snd = snd; |
988 |
|
this.fn = fn; this.dst = dst; |
989 |
|
this.executor = executor; |
1027 |
|
private static final long serialVersionUID = 5232453952276885070L; |
1028 |
|
} |
1029 |
|
|
1030 |
< |
static final class OrAcceptCompletion<T> extends Completion { |
1030 |
> |
static final class AcceptEither<T> extends Completion { |
1031 |
|
final CompletableFuture<? extends T> src; |
1032 |
|
final CompletableFuture<? extends T> snd; |
1033 |
|
final Consumer<? super T> fn; |
1034 |
|
final CompletableFuture<Void> dst; |
1035 |
|
final Executor executor; |
1036 |
< |
OrAcceptCompletion(CompletableFuture<? extends T> src, |
1037 |
< |
CompletableFuture<? extends T> snd, |
1038 |
< |
Consumer<? super T> fn, |
1039 |
< |
CompletableFuture<Void> dst, Executor executor) { |
1036 |
> |
AcceptEither(CompletableFuture<? extends T> src, |
1037 |
> |
CompletableFuture<? extends T> snd, |
1038 |
> |
Consumer<? super T> fn, |
1039 |
> |
CompletableFuture<Void> dst, |
1040 |
> |
Executor executor) { |
1041 |
|
this.src = src; this.snd = snd; |
1042 |
|
this.fn = fn; this.dst = dst; |
1043 |
|
this.executor = executor; |
1080 |
|
private static final long serialVersionUID = 5232453952276885070L; |
1081 |
|
} |
1082 |
|
|
1083 |
< |
static final class OrRunCompletion<T> extends Completion { |
1083 |
> |
static final class RunAfterEither<T> extends Completion { |
1084 |
|
final CompletableFuture<? extends T> src; |
1085 |
|
final CompletableFuture<?> snd; |
1086 |
|
final Runnable fn; |
1087 |
|
final CompletableFuture<Void> dst; |
1088 |
|
final Executor executor; |
1089 |
< |
OrRunCompletion(CompletableFuture<? extends T> src, |
1090 |
< |
CompletableFuture<?> snd, |
1091 |
< |
Runnable fn, |
1092 |
< |
CompletableFuture<Void> dst, Executor executor) { |
1089 |
> |
RunAfterEither(CompletableFuture<? extends T> src, |
1090 |
> |
CompletableFuture<?> snd, |
1091 |
> |
Runnable fn, |
1092 |
> |
CompletableFuture<Void> dst, |
1093 |
> |
Executor executor) { |
1094 |
|
this.src = src; this.snd = snd; |
1095 |
|
this.fn = fn; this.dst = dst; |
1096 |
|
this.executor = executor; |
1293 |
|
private static final long serialVersionUID = 5232453952276885070L; |
1294 |
|
} |
1295 |
|
|
1296 |
< |
static final class ComposeCompletion<T,U> extends Completion { |
1296 |
> |
static final class ThenCompose<T,U> extends Completion { |
1297 |
|
final CompletableFuture<? extends T> src; |
1298 |
|
final Function<? super T, CompletableFuture<U>> fn; |
1299 |
|
final CompletableFuture<U> dst; |
1300 |
|
final Executor executor; |
1301 |
< |
ComposeCompletion(CompletableFuture<? extends T> src, |
1302 |
< |
Function<? super T, CompletableFuture<U>> fn, |
1303 |
< |
CompletableFuture<U> dst, Executor executor) { |
1301 |
> |
ThenCompose(CompletableFuture<? extends T> src, |
1302 |
> |
Function<? super T, CompletableFuture<U>> fn, |
1303 |
> |
CompletableFuture<U> dst, |
1304 |
> |
Executor executor) { |
1305 |
|
this.src = src; this.fn = fn; this.dst = dst; |
1306 |
|
this.executor = executor; |
1307 |
|
} |
1694 |
|
Executor e) { |
1695 |
|
if (fn == null) throw new NullPointerException(); |
1696 |
|
CompletableFuture<U> dst = new CompletableFuture<U>(); |
1697 |
< |
ApplyCompletion<T,U> d = null; |
1697 |
> |
ThenApply<T,U> d = null; |
1698 |
|
Object r; |
1699 |
|
if ((r = result) == null) { |
1700 |
|
CompletionNode p = new CompletionNode |
1701 |
< |
(d = new ApplyCompletion<T,U>(this, fn, dst, e)); |
1701 |
> |
(d = new ThenApply<T,U>(this, fn, dst, e)); |
1702 |
|
while ((r = result) == null) { |
1703 |
|
if (UNSAFE.compareAndSwapObject |
1704 |
|
(this, COMPLETIONS, p.next = completions, p)) |
1797 |
|
Executor e) { |
1798 |
|
if (fn == null) throw new NullPointerException(); |
1799 |
|
CompletableFuture<Void> dst = new CompletableFuture<Void>(); |
1800 |
< |
AcceptCompletion<T> d = null; |
1800 |
> |
ThenAccept<T> d = null; |
1801 |
|
Object r; |
1802 |
|
if ((r = result) == null) { |
1803 |
|
CompletionNode p = new CompletionNode |
1804 |
< |
(d = new AcceptCompletion<T>(this, fn, dst, e)); |
1804 |
> |
(d = new ThenAccept<T>(this, fn, dst, e)); |
1805 |
|
while ((r = result) == null) { |
1806 |
|
if (UNSAFE.compareAndSwapObject |
1807 |
|
(this, COMPLETIONS, p.next = completions, p)) |
1897 |
|
Executor e) { |
1898 |
|
if (action == null) throw new NullPointerException(); |
1899 |
|
CompletableFuture<Void> dst = new CompletableFuture<Void>(); |
1900 |
< |
RunCompletion<T> d = null; |
1900 |
> |
ThenRun<T> d = null; |
1901 |
|
Object r; |
1902 |
|
if ((r = result) == null) { |
1903 |
|
CompletionNode p = new CompletionNode |
1904 |
< |
(d = new RunCompletion<T>(this, action, dst, e)); |
1904 |
> |
(d = new ThenRun<T>(this, action, dst, e)); |
1905 |
|
while ((r = result) == null) { |
1906 |
|
if (UNSAFE.compareAndSwapObject |
1907 |
|
(this, COMPLETIONS, p.next = completions, p)) |
1950 |
|
public <U,V> CompletableFuture<V> thenCombine |
1951 |
|
(CompletableFuture<? extends U> other, |
1952 |
|
BiFunction<? super T,? super U,? extends V> fn) { |
1953 |
< |
return doThenBiApply(other, fn, null); |
1953 |
> |
return doThenCombine(other, fn, null); |
1954 |
|
} |
1955 |
|
|
1956 |
|
/** |
1973 |
|
public <U,V> CompletableFuture<V> thenCombineAsync |
1974 |
|
(CompletableFuture<? extends U> other, |
1975 |
|
BiFunction<? super T,? super U,? extends V> fn) { |
1976 |
< |
return doThenBiApply(other, fn, ForkJoinPool.commonPool()); |
1976 |
> |
return doThenCombine(other, fn, ForkJoinPool.commonPool()); |
1977 |
|
} |
1978 |
|
|
1979 |
|
/** |
1998 |
|
BiFunction<? super T,? super U,? extends V> fn, |
1999 |
|
Executor executor) { |
2000 |
|
if (executor == null) throw new NullPointerException(); |
2001 |
< |
return doThenBiApply(other, fn, executor); |
2001 |
> |
return doThenCombine(other, fn, executor); |
2002 |
|
} |
2003 |
|
|
2004 |
< |
private <U,V> CompletableFuture<V> doThenBiApply |
2004 |
> |
private <U,V> CompletableFuture<V> doThenCombine |
2005 |
|
(CompletableFuture<? extends U> other, |
2006 |
|
BiFunction<? super T,? super U,? extends V> fn, |
2007 |
|
Executor e) { |
2008 |
|
if (other == null || fn == null) throw new NullPointerException(); |
2009 |
|
CompletableFuture<V> dst = new CompletableFuture<V>(); |
2010 |
< |
BiApplyCompletion<T,U,V> d = null; |
2010 |
> |
ThenCombine<T,U,V> d = null; |
2011 |
|
Object r, s = null; |
2012 |
|
if ((r = result) == null || (s = other.result) == null) { |
2013 |
< |
d = new BiApplyCompletion<T,U,V>(this, other, fn, dst, e); |
2013 |
> |
d = new ThenCombine<T,U,V>(this, other, fn, dst, e); |
2014 |
|
CompletionNode q = null, p = new CompletionNode(d); |
2015 |
|
while ((r == null && (r = result) == null) || |
2016 |
|
(s == null && (s = other.result) == null)) { |
2054 |
|
if (ex == null) { |
2055 |
|
try { |
2056 |
|
if (e != null) |
2057 |
< |
e.execute(new AsyncBiApply<T,U,V>(t, u, fn, dst)); |
2057 |
> |
e.execute(new AsyncCombine<T,U,V>(t, u, fn, dst)); |
2058 |
|
else |
2059 |
|
v = fn.apply(t, u); |
2060 |
|
} catch (Throwable rex) { |
2088 |
|
public <U> CompletableFuture<Void> thenAcceptBoth |
2089 |
|
(CompletableFuture<? extends U> other, |
2090 |
|
BiConsumer<? super T, ? super U> block) { |
2091 |
< |
return doThenBiAccept(other, block, null); |
2091 |
> |
return doThenAcceptBoth(other, block, null); |
2092 |
|
} |
2093 |
|
|
2094 |
|
/** |
2111 |
|
public <U> CompletableFuture<Void> thenAcceptBothAsync |
2112 |
|
(CompletableFuture<? extends U> other, |
2113 |
|
BiConsumer<? super T, ? super U> block) { |
2114 |
< |
return doThenBiAccept(other, block, ForkJoinPool.commonPool()); |
2114 |
> |
return doThenAcceptBoth(other, block, ForkJoinPool.commonPool()); |
2115 |
|
} |
2116 |
|
|
2117 |
|
/** |
2136 |
|
BiConsumer<? super T, ? super U> block, |
2137 |
|
Executor executor) { |
2138 |
|
if (executor == null) throw new NullPointerException(); |
2139 |
< |
return doThenBiAccept(other, block, executor); |
2139 |
> |
return doThenAcceptBoth(other, block, executor); |
2140 |
|
} |
2141 |
|
|
2142 |
< |
private <U> CompletableFuture<Void> doThenBiAccept |
2142 |
> |
private <U> CompletableFuture<Void> doThenAcceptBoth |
2143 |
|
(CompletableFuture<? extends U> other, |
2144 |
|
BiConsumer<? super T,? super U> fn, |
2145 |
|
Executor e) { |
2146 |
|
if (other == null || fn == null) throw new NullPointerException(); |
2147 |
|
CompletableFuture<Void> dst = new CompletableFuture<Void>(); |
2148 |
< |
BiAcceptCompletion<T,U> d = null; |
2148 |
> |
ThenAcceptBoth<T,U> d = null; |
2149 |
|
Object r, s = null; |
2150 |
|
if ((r = result) == null || (s = other.result) == null) { |
2151 |
< |
d = new BiAcceptCompletion<T,U>(this, other, fn, dst, e); |
2151 |
> |
d = new ThenAcceptBoth<T,U>(this, other, fn, dst, e); |
2152 |
|
CompletionNode q = null, p = new CompletionNode(d); |
2153 |
|
while ((r == null && (r = result) == null) || |
2154 |
|
(s == null && (s = other.result) == null)) { |
2191 |
|
if (ex == null) { |
2192 |
|
try { |
2193 |
|
if (e != null) |
2194 |
< |
e.execute(new AsyncBiAccept<T,U>(t, u, fn, dst)); |
2194 |
> |
e.execute(new AsyncAcceptBoth<T,U>(t, u, fn, dst)); |
2195 |
|
else |
2196 |
|
fn.accept(t, u); |
2197 |
|
} catch (Throwable rex) { |
2223 |
|
*/ |
2224 |
|
public CompletableFuture<Void> runAfterBoth(CompletableFuture<?> other, |
2225 |
|
Runnable action) { |
2226 |
< |
return doThenBiRun(other, action, null); |
2226 |
> |
return doRunAfterBoth(other, action, null); |
2227 |
|
} |
2228 |
|
|
2229 |
|
/** |
2244 |
|
*/ |
2245 |
|
public CompletableFuture<Void> runAfterBothAsync(CompletableFuture<?> other, |
2246 |
|
Runnable action) { |
2247 |
< |
return doThenBiRun(other, action, ForkJoinPool.commonPool()); |
2247 |
> |
return doRunAfterBoth(other, action, ForkJoinPool.commonPool()); |
2248 |
|
} |
2249 |
|
|
2250 |
|
/** |
2268 |
|
Runnable action, |
2269 |
|
Executor executor) { |
2270 |
|
if (executor == null) throw new NullPointerException(); |
2271 |
< |
return doThenBiRun(other, action, executor); |
2271 |
> |
return doRunAfterBoth(other, action, executor); |
2272 |
|
} |
2273 |
|
|
2274 |
< |
private CompletableFuture<Void> doThenBiRun(CompletableFuture<?> other, |
2275 |
< |
Runnable action, |
2276 |
< |
Executor e) { |
2274 |
> |
private CompletableFuture<Void> doRunAfterBoth(CompletableFuture<?> other, |
2275 |
> |
Runnable action, |
2276 |
> |
Executor e) { |
2277 |
|
if (other == null || action == null) throw new NullPointerException(); |
2278 |
|
CompletableFuture<Void> dst = new CompletableFuture<Void>(); |
2279 |
< |
BiRunCompletion<T> d = null; |
2279 |
> |
RunAfterBoth<T> d = null; |
2280 |
|
Object r, s = null; |
2281 |
|
if ((r = result) == null || (s = other.result) == null) { |
2282 |
< |
d = new BiRunCompletion<T>(this, other, action, dst, e); |
2282 |
> |
d = new RunAfterBoth<T>(this, other, action, dst, e); |
2283 |
|
CompletionNode q = null, p = new CompletionNode(d); |
2284 |
|
while ((r == null && (r = result) == null) || |
2285 |
|
(s == null && (s = other.result) == null)) { |
2347 |
|
public <U> CompletableFuture<U> applyToEither |
2348 |
|
(CompletableFuture<? extends T> other, |
2349 |
|
Function<? super T, U> fn) { |
2350 |
< |
return doOrApply(other, fn, null); |
2350 |
> |
return doApplyToEither(other, fn, null); |
2351 |
|
} |
2352 |
|
|
2353 |
|
/** |
2374 |
|
public <U> CompletableFuture<U> applyToEitherAsync |
2375 |
|
(CompletableFuture<? extends T> other, |
2376 |
|
Function<? super T, U> fn) { |
2377 |
< |
return doOrApply(other, fn, ForkJoinPool.commonPool()); |
2377 |
> |
return doApplyToEither(other, fn, ForkJoinPool.commonPool()); |
2378 |
|
} |
2379 |
|
|
2380 |
|
/** |
2404 |
|
Function<? super T, U> fn, |
2405 |
|
Executor executor) { |
2406 |
|
if (executor == null) throw new NullPointerException(); |
2407 |
< |
return doOrApply(other, fn, executor); |
2407 |
> |
return doApplyToEither(other, fn, executor); |
2408 |
|
} |
2409 |
|
|
2410 |
< |
private <U> CompletableFuture<U> doOrApply |
2410 |
> |
private <U> CompletableFuture<U> doApplyToEither |
2411 |
|
(CompletableFuture<? extends T> other, |
2412 |
|
Function<? super T, U> fn, |
2413 |
|
Executor e) { |
2414 |
|
if (other == null || fn == null) throw new NullPointerException(); |
2415 |
|
CompletableFuture<U> dst = new CompletableFuture<U>(); |
2416 |
< |
OrApplyCompletion<T,U> d = null; |
2416 |
> |
ApplyToEither<T,U> d = null; |
2417 |
|
Object r; |
2418 |
|
if ((r = result) == null && (r = other.result) == null) { |
2419 |
< |
d = new OrApplyCompletion<T,U>(this, other, fn, dst, e); |
2419 |
> |
d = new ApplyToEither<T,U>(this, other, fn, dst, e); |
2420 |
|
CompletionNode q = null, p = new CompletionNode(d); |
2421 |
|
while ((r = result) == null && (r = other.result) == null) { |
2422 |
|
if (q != null) { |
2482 |
|
public CompletableFuture<Void> acceptEither |
2483 |
|
(CompletableFuture<? extends T> other, |
2484 |
|
Consumer<? super T> block) { |
2485 |
< |
return doOrAccept(other, block, null); |
2485 |
> |
return doAcceptEither(other, block, null); |
2486 |
|
} |
2487 |
|
|
2488 |
|
/** |
2509 |
|
public CompletableFuture<Void> acceptEitherAsync |
2510 |
|
(CompletableFuture<? extends T> other, |
2511 |
|
Consumer<? super T> block) { |
2512 |
< |
return doOrAccept(other, block, ForkJoinPool.commonPool()); |
2512 |
> |
return doAcceptEither(other, block, ForkJoinPool.commonPool()); |
2513 |
|
} |
2514 |
|
|
2515 |
|
/** |
2539 |
|
Consumer<? super T> block, |
2540 |
|
Executor executor) { |
2541 |
|
if (executor == null) throw new NullPointerException(); |
2542 |
< |
return doOrAccept(other, block, executor); |
2542 |
> |
return doAcceptEither(other, block, executor); |
2543 |
|
} |
2544 |
|
|
2545 |
< |
private CompletableFuture<Void> doOrAccept |
2545 |
> |
private CompletableFuture<Void> doAcceptEither |
2546 |
|
(CompletableFuture<? extends T> other, |
2547 |
|
Consumer<? super T> fn, |
2548 |
|
Executor e) { |
2549 |
|
if (other == null || fn == null) throw new NullPointerException(); |
2550 |
|
CompletableFuture<Void> dst = new CompletableFuture<Void>(); |
2551 |
< |
OrAcceptCompletion<T> d = null; |
2551 |
> |
AcceptEither<T> d = null; |
2552 |
|
Object r; |
2553 |
|
if ((r = result) == null && (r = other.result) == null) { |
2554 |
< |
d = new OrAcceptCompletion<T>(this, other, fn, dst, e); |
2554 |
> |
d = new AcceptEither<T>(this, other, fn, dst, e); |
2555 |
|
CompletionNode q = null, p = new CompletionNode(d); |
2556 |
|
while ((r = result) == null && (r = other.result) == null) { |
2557 |
|
if (q != null) { |
2614 |
|
*/ |
2615 |
|
public CompletableFuture<Void> runAfterEither(CompletableFuture<?> other, |
2616 |
|
Runnable action) { |
2617 |
< |
return doOrRun(other, action, null); |
2617 |
> |
return doRunAfterEither(other, action, null); |
2618 |
|
} |
2619 |
|
|
2620 |
|
/** |
2640 |
|
public CompletableFuture<Void> runAfterEitherAsync |
2641 |
|
(CompletableFuture<?> other, |
2642 |
|
Runnable action) { |
2643 |
< |
return doOrRun(other, action, ForkJoinPool.commonPool()); |
2643 |
> |
return doRunAfterEither(other, action, ForkJoinPool.commonPool()); |
2644 |
|
} |
2645 |
|
|
2646 |
|
/** |
2669 |
|
Runnable action, |
2670 |
|
Executor executor) { |
2671 |
|
if (executor == null) throw new NullPointerException(); |
2672 |
< |
return doOrRun(other, action, executor); |
2672 |
> |
return doRunAfterEither(other, action, executor); |
2673 |
|
} |
2674 |
|
|
2675 |
< |
private CompletableFuture<Void> doOrRun(CompletableFuture<?> other, |
2676 |
< |
Runnable action, |
2677 |
< |
Executor e) { |
2675 |
> |
private CompletableFuture<Void> doRunAfterEither |
2676 |
> |
(CompletableFuture<?> other, |
2677 |
> |
Runnable action, |
2678 |
> |
Executor e) { |
2679 |
|
if (other == null || action == null) throw new NullPointerException(); |
2680 |
|
CompletableFuture<Void> dst = new CompletableFuture<Void>(); |
2681 |
< |
OrRunCompletion<T> d = null; |
2681 |
> |
RunAfterEither<T> d = null; |
2682 |
|
Object r; |
2683 |
|
if ((r = result) == null && (r = other.result) == null) { |
2684 |
< |
d = new OrRunCompletion<T>(this, other, action, dst, e); |
2684 |
> |
d = new RunAfterEither<T>(this, other, action, dst, e); |
2685 |
|
CompletionNode q = null, p = new CompletionNode(d); |
2686 |
|
while ((r = result) == null && (r = other.result) == null) { |
2687 |
|
if (q != null) { |
2734 |
|
*/ |
2735 |
|
public <U> CompletableFuture<U> thenCompose |
2736 |
|
(Function<? super T, CompletableFuture<U>> fn) { |
2737 |
< |
return doCompose(fn, null); |
2737 |
> |
return doThenCompose(fn, null); |
2738 |
|
} |
2739 |
|
|
2740 |
|
/** |
2754 |
|
*/ |
2755 |
|
public <U> CompletableFuture<U> thenComposeAsync |
2756 |
|
(Function<? super T, CompletableFuture<U>> fn) { |
2757 |
< |
return doCompose(fn, ForkJoinPool.commonPool()); |
2757 |
> |
return doThenCompose(fn, ForkJoinPool.commonPool()); |
2758 |
|
} |
2759 |
|
|
2760 |
|
/** |
2776 |
|
(Function<? super T, CompletableFuture<U>> fn, |
2777 |
|
Executor executor) { |
2778 |
|
if (executor == null) throw new NullPointerException(); |
2779 |
< |
return doCompose(fn, executor); |
2779 |
> |
return doThenCompose(fn, executor); |
2780 |
|
} |
2781 |
|
|
2782 |
< |
private <U> CompletableFuture<U> doCompose |
2782 |
> |
private <U> CompletableFuture<U> doThenCompose |
2783 |
|
(Function<? super T, CompletableFuture<U>> fn, |
2784 |
|
Executor e) { |
2785 |
|
if (fn == null) throw new NullPointerException(); |
2786 |
|
CompletableFuture<U> dst = null; |
2787 |
< |
ComposeCompletion<T,U> d = null; |
2787 |
> |
ThenCompose<T,U> d = null; |
2788 |
|
Object r; |
2789 |
|
if ((r = result) == null) { |
2790 |
|
dst = new CompletableFuture<U>(); |
2791 |
|
CompletionNode p = new CompletionNode |
2792 |
< |
(d = new ComposeCompletion<T,U>(this, fn, dst, e)); |
2792 |
> |
(d = new ThenCompose<T,U>(this, fn, dst, e)); |
2793 |
|
while ((r = result) == null) { |
2794 |
|
if (UNSAFE.compareAndSwapObject |
2795 |
|
(this, COMPLETIONS, p.next = completions, p)) |