com.cmonbaby.http.rxjava.CallExecuteOnSubscribe Maven / Gradle / Ivy
Show all versions of http_lower Show documentation
package com.cmonbaby.http.rxjava;
import retrofit2.Call;
import retrofit2.Response;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.exceptions.Exceptions;
/**
* Author: Simon
*
QO: 8950764
*
Email: [email protected]
*
WebSize: https://www.cmonbaby.com
*
Version: 1.0.0
*
Date: 2020/12/28
*
Description:
*/
final class CallExecuteOnSubscribe implements OnSubscribe> {
private final Call originalCall;
CallExecuteOnSubscribe(Call originalCall) {
this.originalCall = originalCall;
}
@Override
public void call(Subscriber super Response> subscriber) {
// Since Call is a one-shot type, clone it for each new subscriber.
Call call = originalCall.clone();
CallArbiter arbiter = new CallArbiter<>(call, subscriber);
subscriber.add(arbiter);
subscriber.setProducer(arbiter);
Response response;
try {
response = call.execute();
} catch (Throwable t) {
Exceptions.throwIfFatal(t);
arbiter.emitError(t);
return;
}
arbiter.emitResponse(response);
}
}