touch-ups

This commit is contained in:
Bruce Eckel 2017-01-02 14:22:25 -08:00
parent 8268b577c9
commit 45d4e5d85b
4 changed files with 12 additions and 12 deletions

View File

@ -14,16 +14,16 @@ public class Batter {
new Nap(100);
return ingredient;
}
static <T> CompletableFuture<T> cf(T ingredient) {
static <T> CompletableFuture<T> prep(T ingredient) {
return CompletableFuture
.completedFuture(ingredient)
.thenApply(Batter::prepare);
.thenApplyAsync(Batter::prepare);
}
public static CompletableFuture<Batter> mix() {
CompletableFuture<Eggs> eggs = cf(new Eggs());
CompletableFuture<Milk> milk = cf(new Milk());
CompletableFuture<Sugar> sugar = cf(new Sugar());
CompletableFuture<Flour> flour = cf(new Flour());
CompletableFuture<Eggs> eggs = prep(new Eggs());
CompletableFuture<Milk> milk = prep(new Milk());
CompletableFuture<Sugar> sugar = prep(new Sugar());
CompletableFuture<Flour> flour = prep(new Flour());
CompletableFuture
.allOf(eggs, milk, sugar, flour)
.join();

View File

@ -7,8 +7,8 @@ import onjava.Nap;
public class CatchCompletableExceptions {
static void handleException(int failcount) {
// Call Function only if there's an exception,
// Must produce same type as came in:
// Call the Function only if there's an
// exception, must produce same type as came in:
CompletableExceptions
.test("exceptionally", failcount)
.exceptionally((ex) -> { // Function

View File

@ -7,8 +7,8 @@ import java.util.concurrent.*;
public class CompletedMachina {
public static void main(String[] args) {
CompletableFuture<Machina> cf =
CompletableFuture.completedFuture(
new Machina(0));
CompletableFuture.completedFuture(
new Machina(0));
try {
Machina m = cf.get(); // Doesn't block
} catch(InterruptedException |

View File

@ -26,7 +26,7 @@ public class FrostedCake {
.thenCombineAsync(Frosting.make(),
(cake, frosting) ->
new FrostedCake(cake, frosting))
.thenAcceptAsync(System.out::println).join());
// Need to rewrite...
.thenAcceptAsync(System.out::println)
.join());
}
}