package com.qianwen.core.http;
|
|
import java.io.IOException;
|
import java.util.function.BiConsumer;
|
import java.util.function.Consumer;
|
import okhttp3.Call;
|
import okhttp3.Request;
|
|
/* loaded from: blade-starter-http-9.3.0.0-SNAPSHOT.jar:org/springblade/core/http/AsyncCall.class */
|
public class AsyncCall {
|
private static final Consumer<ResponseSpec> DEFAULT_CONSUMER = r -> {
|
};
|
private static final BiConsumer<Request, IOException> DEFAULT_FAIL_CONSUMER = (r, e) -> {
|
|
};
|
private final Call call;
|
private Consumer<ResponseSpec> successConsumer = DEFAULT_CONSUMER;
|
private Consumer<ResponseSpec> responseConsumer = DEFAULT_CONSUMER;
|
private BiConsumer<Request, IOException> failedBiConsumer = DEFAULT_FAIL_CONSUMER;
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
public AsyncCall(Call call) {
|
this.call = call;
|
}
|
|
public void onSuccessful(Consumer<ResponseSpec> consumer) {
|
this.successConsumer = consumer;
|
execute();
|
}
|
|
public void onResponse(Consumer<ResponseSpec> consumer) {
|
this.responseConsumer = consumer;
|
execute();
|
}
|
|
public AsyncCall onFailed(BiConsumer<Request, IOException> biConsumer) {
|
this.failedBiConsumer = biConsumer;
|
return this;
|
}
|
|
private void execute() {
|
this.call.enqueue(new AsyncCallback(this));
|
}
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
public void onResponse(HttpResponse httpResponse) {
|
this.responseConsumer.accept(httpResponse);
|
}
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
public void onSuccessful(HttpResponse httpResponse) {
|
this.successConsumer.accept(httpResponse);
|
}
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
public void onFailure(Request request, IOException e) {
|
this.failedBiConsumer.accept(request, e);
|
}
|
}
|