Java Reference
In-Depth Information
Things look a bit more complex this time, so try to understand what's going on here, step by step.
The sequence of these three transformations is depicted in figure 11.5 .
Figure 11.5. Composing synchronous operations and asynchronous
tasks
You're performing the same three map operations as you did in the synchronous solution of
listing 11.15 , but you make those operations asynchronous when necessary, using the feature
provided by the CompletableFuture class.
Getting the prices
You've already seen the first of these three operations in various examples in this chapter; you
just query the shop asynchronously by passing a lambda expression to the supplyAsync factory
method. The result of this first transformation is a Stream<Completable-Future<String>>,
where each CompletableFuture will contain, once completed, the String returned by the
corresponding shop. Note that you configure the CompletableFutures with the custom Executor
developed in listing 11.12 .
 
Search WWH ::




Custom Search