-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample6.java
More file actions
32 lines (28 loc) · 1.25 KB
/
Example6.java
File metadata and controls
32 lines (28 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Example6 {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CompletableFuture<String> basePrep = CompletableFuture.supplyAsync(() -> {
System.out.println("Preparar Base");
return "Base Lista!!!";
});
CompletableFuture<String> topPrep = CompletableFuture.supplyAsync(() -> {
System.out.println("Agregar toppings");
return "Toppings Listos!!!";
});
CompletableFuture<String> foodPrep = basePrep.thenCombine(topPrep,(baseResponse,topResponse) ->{
System.out.println("Toppings y Base son::"+baseResponse+":"+topResponse);
return "Pizza Lista!!!";
});
CompletableFuture<String> foodServe = foodPrep.thenCompose(food ->{
System.out.println("Servir comida");
return CompletableFuture.supplyAsync(()->"Comida servida");
});
CompletableFuture<String> order = foodServe.thenApply(orderComplete -> "Orden completa.."+orderComplete);
try{
System.out.println(order.get());
}catch (Exception e){
e.printStackTrace();
}
}
}