Skip to content

ENH: Add HttpCall that allows client to choose async or sync processing of request #21

Closed
@rbygrave

Description

@rbygrave

Along the same lines as Retrofit Call, this allows the client code to choose if they wish to execute asynchronously (CompletableFuture) or synchronously.

package io.avaje.http.client;

import java.util.concurrent.CompletableFuture;

/**
 * Allows for executing the request asynchronously or synchronously.
 *
 * @param <E> The type of response
 */
public interface HttpCall<E> {

  /**
   * Execute the request returning the result.
   */
  E execute();

  /**
   * Execute the request asynchronously.
   */
  CompletableFuture<E> async();
}

Example

HttpCall<Stream<Customer>> call = clientContext.request()
      .path("customers/stream")
      .GET()
      .call()


// call synchronously
Stream<Customer> customers = call.execute();

// call asynchronously
call
  .async()
  .whenComplete((stream, throwable) -> {
      ...
    });

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions