Skip to content

Instantly share code, notes, and snippets.

@viveknaskar
Created September 18, 2022 15:23
Show Gist options
  • Save viveknaskar/c1c8eae45fa3999b0947bfc884edcf10 to your computer and use it in GitHub Desktop.
Save viveknaskar/c1c8eae45fa3999b0947bfc884edcf10 to your computer and use it in GitHub Desktop.
Simplest example of CompletableFuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class SimpleCompletableFutureExample {
public static void main(String[] args) {
CompletableFuture<String> completableFuture = new CompletableFuture<>();
try {
// we can get the result using CompletableFuture.get()
completableFuture.get();
// we can force complete a completable future
completableFuture.complete("some dummy data from Future");
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment