added return operations

This commit is contained in:
Bruce Eckel 2017-01-02 14:21:29 -08:00
parent 65246aea15
commit 5de72c00d7

View File

@ -3,6 +3,7 @@
// We make no guarantees that this code is fit for any purpose. // We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information. // Visit http://OnJava8.com for more book information.
import java.util.concurrent.*; import java.util.concurrent.*;
import static onjava.CompletableUtilities.*;
public class DualCompletableOperations { public class DualCompletableOperations {
static CompletableFuture<Workable> cfA, cfB; static CompletableFuture<Workable> cfA, cfB;
@ -17,41 +18,41 @@ public class DualCompletableOperations {
} }
public static void main(String[] args) { public static void main(String[] args) {
init(); init();
cfA.runAfterEitherAsync(cfB, () -> voidr(cfA.runAfterEitherAsync(cfB, () ->
System.out.println("runAfterEither")); System.out.println("runAfterEither")));
join(); join();
init(); init();
cfA.runAfterBothAsync(cfB, () -> voidr(cfA.runAfterBothAsync(cfB, () ->
System.out.println("runAfterBoth")); System.out.println("runAfterBoth")));
join(); join();
init(); init();
cfA.applyToEitherAsync(cfB, w -> { showr(cfA.applyToEitherAsync(cfB, w -> {
System.out.println("applyToEither: " + w); System.out.println("applyToEither: " + w);
return w; return w;
}); }));
join(); join();
init(); init();
cfA.acceptEitherAsync(cfB, w -> { voidr(cfA.acceptEitherAsync(cfB, w -> {
System.out.println("acceptEither: " + w); System.out.println("acceptEither: " + w);
}); }));
join(); join();
init(); init();
cfA.thenAcceptBothAsync(cfB, (w1, w2) -> { voidr(cfA.thenAcceptBothAsync(cfB, (w1, w2) -> {
System.out.println("thenAcceptBoth: " System.out.println("thenAcceptBoth: "
+ w1 + ", " + w2); + w1 + ", " + w2);
}); }));
join(); join();
init(); init();
cfA.thenCombineAsync(cfB, (w1, w2) -> { showr(cfA.thenCombineAsync(cfB, (w1, w2) -> {
System.out.println("thenCombine: " System.out.println("thenCombine: "
+ w1 + ", " + w2); + w1 + ", " + w2);
return w1; return w1;
}); }));
join(); join();
init(); init();
@ -79,10 +80,11 @@ Workable[AW]
***************** *****************
Workable[BW] Workable[BW]
Workable[AW] Workable[AW]
*****************
runAfterBoth runAfterBoth
*****************
Workable[BW] Workable[BW]
applyToEither: Workable[BW] applyToEither: Workable[BW]
Workable[BW]
Workable[AW] Workable[AW]
***************** *****************
Workable[BW] Workable[BW]
@ -91,21 +93,22 @@ Workable[AW]
***************** *****************
Workable[BW] Workable[BW]
Workable[AW] Workable[AW]
*****************
thenAcceptBoth: Workable[AW], Workable[BW] thenAcceptBoth: Workable[AW], Workable[BW]
*****************
Workable[BW] Workable[BW]
Workable[AW] Workable[AW]
*****************
thenCombine: Workable[AW], Workable[BW] thenCombine: Workable[AW], Workable[BW]
Workable[AW]
*****************
Workable[CW] Workable[CW]
anyOf anyOf
Workable[DW]
Workable[BW] Workable[BW]
Workable[DW]
Workable[AW] Workable[AW]
***************** *****************
Workable[CW] Workable[CW]
Workable[DW]
Workable[BW] Workable[BW]
Workable[DW]
Workable[AW] Workable[AW]
***************** *****************
allOf allOf