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

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

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

import retrofit2.Response;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.exceptions.Exceptions;
import rx.exceptions.OnCompletedFailedException;
import rx.exceptions.OnErrorFailedException;
import rx.exceptions.OnErrorNotImplementedException;

/**
 * 

Author: Simon *

QO: 8950764 *

Email: [email protected] *

WebSize: https://www.cmonbaby.com *

Version: 1.0.0 *

Date: 2020/12/28 *

Description: */ final class ResultOnSubscribe implements OnSubscribe> { private final OnSubscribe> upstream; ResultOnSubscribe(OnSubscribe> upstream) { this.upstream = upstream; } @Override public void call(Subscriber> subscriber) { upstream.call(new ResultSubscriber<>(subscriber)); } private static class ResultSubscriber extends Subscriber> { private final Subscriber> subscriber; ResultSubscriber(Subscriber> subscriber) { super(subscriber); this.subscriber = subscriber; } @Override public void onNext(Response response) { subscriber.onNext(Result.response(response)); } @Override public void onError(Throwable throwable) { try { subscriber.onNext(Result.error(throwable)); } catch (Throwable t) { try { subscriber.onError(t); } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) { e.printStackTrace(); } catch (Throwable inner) { Exceptions.throwIfFatal(inner); inner.printStackTrace(); } return; } subscriber.onCompleted(); } @Override public void onCompleted() { subscriber.onCompleted(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy