All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.openunirest.http.async.CallbackFuture Maven / Gradle / Ivy

There is a newer version: 2.5.03
Show newest version
package io.github.openunirest.http.async;

import io.github.openunirest.http.HttpResponse;
import io.github.openunirest.http.exceptions.UnirestException;

import java.util.concurrent.CompletableFuture;

public class CallbackFuture  {

    public static  CompletableFuture> wrap(Callback source){
        return new CompletableFuture>(){
            @Override
            public boolean complete(HttpResponse value) {
                source.completed(value);
                return super.complete(value);
            }
            @Override
            public boolean completeExceptionally(Throwable ex) {
                source.failed(new UnirestException(ex));
                return super.completeExceptionally(ex);
            }
            @Override
            public boolean cancel(boolean mayInterruptIfRunning) {
                source.cancelled();
                return super.cancel(mayInterruptIfRunning);
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy