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

com.cmonbaby.http.rxjava.CallEnqueueOnSubscribe Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.cmonbaby.http.rxjava;

import androidx.annotation.NonNull;

import retrofit2.Call;
import retrofit2.Callback;
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 CallEnqueueOnSubscribe implements OnSubscribe> { private final Call originalCall; CallEnqueueOnSubscribe(Call originalCall) { this.originalCall = originalCall; } @Override public void call(Subscriber> subscriber) { // Since Call is a one-shot type, clone it for each new subscriber. Call call = originalCall.clone(); final CallArbiter arbiter = new CallArbiter<>(call, subscriber); subscriber.add(arbiter); subscriber.setProducer(arbiter); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { arbiter.emitResponse(response); } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { Exceptions.throwIfFatal(t); arbiter.emitError(t); } }); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy