My problem is how to use Completable Future.
I have a class that implements Callable.
public class Executor implements Callable<Collection>
Earlier is used to do -
service.submit(collectorService);
Which would return a Future<Collection>
. However we don't want to use future anymore and need CompletableFuture
. One idea is that we don't need to poll with CompletableFuture and We don't have to wait and block until it's ready.
So how would i use completable future and call a function say isDone()
when the callable
thread finishes.
Given a CompletableFuture<T> f
, you can kick off a synchronous or asynchronous task to run upon completion using:
f.thenApply(result -> isDone(result)); // sync callback
f.thenApplyAsync(result -> isDone(result)); // async callback
...or, if you don't need the result:
f.thenRun(() -> isDone());
f.thenRunAsync(() -> isDone());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With