Is there any chance that by the moment thenApply
/ thenAccept
methods are called for new CompletableFuture object, the future's execution will have already been finished and setting handlers via aforementioned methods won't have any effect? I am not just having these two methods in mind, but the whole bunch of ~50 methods that accept handlers of the CompletableFuture API.
CompletableFuture<String> f = CompletableFuture.supplyAsync(() -> toString());
f.thenApply(s -> f); // will be called if "f" completes before this line is invoked?
Yes.
If a promise has already resolved, any callbacks you add in the future will execute immediately.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.