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

com.vertexvis.example.CallbackUtil Maven / Gradle / Ivy

package com.vertexvis.example;

import com.vertexvis.ApiCallback;
import com.vertexvis.ApiException;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

class CallbackUtil {
  public static  CompletableFuture execute(Consumer> callbackConsumer) {
    CompletableFuture cf = new CompletableFuture<>();

    callbackConsumer.accept(new ApiCallback() {
      @Override
      public void onFailure(ApiException e, int statusCode,
                            Map> responseHeaders) {
        cf.completeExceptionally(e);
      }

      @Override
      public void onSuccess(T result, int statusCode, Map> responseHeaders) {
        cf.complete(result);
      }

      @Override
      public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {

      }

      @Override
      public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {

      }
    });

    return cf;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy