question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Java 8 CompletableFuture

See original GitHub issue

Not 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10

github_iconTop GitHub Comments

1reaction
rybercommented, May 24, 2018

@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

0reactions
rybercommented, Mar 6, 2019

Hello, this should be resolved or addressed in Unirest 2. Please see the upgrade guide for important changes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found