Make asynchronous API calls with enqueue() and reactiveRequest()
masterWhile execute() is used for synchronous calls, the SDK provides two methods for asynchronous execution:
enqueue(): Uses aServiceCallback<T>to handle the response or failure in a background thread.reactiveRequest(): Returns an RxJavaSingle<Response<T>>, allowing for reactive programming patterns.
// Using enqueue() with a callback
service.listEnvironments().enqueue(new ServiceCallback<ListEnvironmentsResponse>() {
@Override
public void onResponse(Response<ListEnvironmentsResponse> response) {
System.out.println("We did it! " + response);
}
@Override
public void onFailure(Exception e) {
System.out.println("Whoops...");
}
});
// Using reactiveRequest() with RxJava
Single<Response<ListEnvironmentsResponse>> observableRequest
= service.listEnvironments().reactiveRequest();
observableRequest
.subscribeOn(Schedulers.single())
.subscribe(response -> System.out.println("We did it with s~t~r~e~a~m~s! " + response));