touch-ups
This commit is contained in:
parent
8268b577c9
commit
45d4e5d85b
@ -14,16 +14,16 @@ public class Batter {
|
|||||||
new Nap(100);
|
new Nap(100);
|
||||||
return ingredient;
|
return ingredient;
|
||||||
}
|
}
|
||||||
static <T> CompletableFuture<T> cf(T ingredient) {
|
static <T> CompletableFuture<T> prep(T ingredient) {
|
||||||
return CompletableFuture
|
return CompletableFuture
|
||||||
.completedFuture(ingredient)
|
.completedFuture(ingredient)
|
||||||
.thenApply(Batter::prepare);
|
.thenApplyAsync(Batter::prepare);
|
||||||
}
|
}
|
||||||
public static CompletableFuture<Batter> mix() {
|
public static CompletableFuture<Batter> mix() {
|
||||||
CompletableFuture<Eggs> eggs = cf(new Eggs());
|
CompletableFuture<Eggs> eggs = prep(new Eggs());
|
||||||
CompletableFuture<Milk> milk = cf(new Milk());
|
CompletableFuture<Milk> milk = prep(new Milk());
|
||||||
CompletableFuture<Sugar> sugar = cf(new Sugar());
|
CompletableFuture<Sugar> sugar = prep(new Sugar());
|
||||||
CompletableFuture<Flour> flour = cf(new Flour());
|
CompletableFuture<Flour> flour = prep(new Flour());
|
||||||
CompletableFuture
|
CompletableFuture
|
||||||
.allOf(eggs, milk, sugar, flour)
|
.allOf(eggs, milk, sugar, flour)
|
||||||
.join();
|
.join();
|
||||||
|
@ -7,8 +7,8 @@ import onjava.Nap;
|
|||||||
|
|
||||||
public class CatchCompletableExceptions {
|
public class CatchCompletableExceptions {
|
||||||
static void handleException(int failcount) {
|
static void handleException(int failcount) {
|
||||||
// Call Function only if there's an exception,
|
// Call the Function only if there's an
|
||||||
// Must produce same type as came in:
|
// exception, must produce same type as came in:
|
||||||
CompletableExceptions
|
CompletableExceptions
|
||||||
.test("exceptionally", failcount)
|
.test("exceptionally", failcount)
|
||||||
.exceptionally((ex) -> { // Function
|
.exceptionally((ex) -> { // Function
|
||||||
|
@ -26,7 +26,7 @@ public class FrostedCake {
|
|||||||
.thenCombineAsync(Frosting.make(),
|
.thenCombineAsync(Frosting.make(),
|
||||||
(cake, frosting) ->
|
(cake, frosting) ->
|
||||||
new FrostedCake(cake, frosting))
|
new FrostedCake(cake, frosting))
|
||||||
.thenAcceptAsync(System.out::println).join());
|
.thenAcceptAsync(System.out::println)
|
||||||
// Need to rewrite...
|
.join());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user