Skip to content

Commit f3d6f32

Browse files
authoredNov 12, 2017
Added meanings for some static methods of CompletableFuture
1 parent 24251c1 commit f3d6f32

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed
 

‎topics/core/java-8.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,18 @@ Also, the program itself becomes more readable.
154154
```java
155155
CompletableFuture.supplyAsync(() -> getStockInfo(“GOOGL”), executor) // if executor is not passed it uses internal pool
156156
.whenComplete((info, exec) -> System.out.println(info)) // triggered once previous operation is finished
157-
.thenApply(Stock::getRate) // thenApply takes input and returns output
158-
.thenAccept(rate -> System.out.println(rate)) // thenAccept takes input, does not return output
159-
.thenRun(() -> System.out.println(“done”))); // thenRun only runs
157+
.thenApply(Stock::getRate)
158+
.thenAccept(rate -> System.out.println(rate))
159+
.thenRun(() -> System.out.println(“done”)));
160160
```
161161

162162
So when you trigger this, it immediately returns the CompletableFuture instance, which can be used to check its status and such.
163163

164-
**Massive API**
165-
166-
- get()
167-
- join()
168-
- getNow(T valIfAbsent)
169-
- cancel()
170-
- isDone()
164+
- supply method takes ```Supplier``` which returns a value
165+
- thenApply method argument is ```Function``` which takes input and returns value
166+
- thenAccept method argument is ```Consumer``` which takes input
167+
- thenRun method argument is ```Runnable``` which only runs
168+
- CompletableFuture has no control of tasks while they are running in the executor. So cancel method just sets returned value as Exceptional.
171169

172170
### StampedLock
173171

0 commit comments

Comments
 (0)
Please sign in to comment.