Support for Java 8 CompletableFuture
See original GitHub issueNot sure if this lib is built on JDK 8, but, if it is, it’d be nice to use CompletableFuture instead of the old Future class:
CompletableFuture<HttpResponse<String>> eventualResponse = Unirest.get("http://").asStringFuture();
eventualResponse.thenAccept(response -> {
//code over here
});
Since Unirest has already a Callback interface, it’d be easy to convert it into a CompletableFuture:
public class CallbackPromise<T> extends CompletableFuture<HttpResponse<T>> implements Callback<T> {
@Override
public void completed(HttpResponse<T> response) {
complete(response);
}
@Override
public void failed(Exception e) {
completeExceptionally(e);
}
@Override
public void cancelled() {
completeExceptionally(new UnirestException("cancelled"));
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:10
Top Results From Across the Web
CompletableFuture (Java Platform SE 8 ) - Oracle Help Center
A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage , supporting dependent functions...
Read more >Guide To CompletableFuture - Baeldung
This tutorial is a guide to the functionality and use cases of the CompletableFuture class that was introduced as a Java 8 Concurrency...
Read more >Java CompletableFuture Tutorial with Examples - CalliCoder
CompletableFuture is used for asynchronous programming in Java. Asynchronous programming is a means of writing non-blocking code by running a ...
Read more >CompletableFuture in Java - Javatpoint
A CompletableFuture is an extension to Java's Future API which was introduced in Java 8. A Future is used for asynchronous Programming. It...
Read more >Futures in Java: CompletableFuture | by Shreyas M N - Medium
CompletableFuture was introduced in Java 8, as an extension of · Future's API. You may wonder why we needed CompletableFuture when there already...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gabfssilva thanks. I’m actually now maintaining an updated fork of this project where I’ve addressed this issue: https://github.com/OpenUnirest/unirest-java
Hello, this should be resolved or addressed in Unirest 2. Please see the upgrade guide for important changes.