File tree 1 file changed +8
-10
lines changed
1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -154,20 +154,18 @@ Also, the program itself becomes more readable.
154
154
``` java
155
155
CompletableFuture . supplyAsync(() - > getStockInfo(“GOOGL ”), executor) // if executor is not passed it uses internal pool
156
156
.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”)));
160
160
```
161
161
162
162
So when you trigger this, it immediately returns the CompletableFuture instance, which can be used to check its status and such.
163
163
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.
171
169
172
170
### StampedLock
173
171
You can’t perform that action at this time.
0 commit comments