Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: nested calling #49

Closed
kdani41 opened this issue Feb 16, 2016 · 4 comments
Closed

Question: nested calling #49

kdani41 opened this issue Feb 16, 2016 · 4 comments

Comments

@kdani41
Copy link

kdani41 commented Feb 16, 2016

Hi,

First off amazing library!!!. Thanks for devoting your time 👍
My question might not be specific to your library but I'm stuck in this small problem. I will really appreciate if you can help.

So, basically what i want to achieve is according to the internet connection I want to fire the api call and to do this I think I have to combine 2 observables (one is from your library and one is mine from the api that i'm using).

My attempt:

new ReactiveNetwork().observeConnectivity(context)
.flatMap(new Func1<ConnectivityStatus, Observable<JSONObject>>() {
            // I want to access subscriber in here.
            @Override
            public Observable<JSONObject> call(ConnectivityStatus connectivityStatus) {

                return null;
            }
        })
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
// I want to use onNext, onError 
.subscribe(this);

Not sure if I'm doing this right but will really appreciate if you can help..
Thanks again for devoting your time!!

@pwittchen
Copy link
Owner

Hi,

Thanks for your question! It's actually not related to this library, but to RxJava and Reactive Programming. I think you should use zip() operator from RxJava library in order to combine two or more Observables. This will allow you to fire API call when internet connection is available without breaking a chain. For calling a RESTful API you can use Retrofit library, which provides RxJava Observables for HTTP responses. You can combine Observable from ReactiveNetwork with Observable from Retrofit. When I find some time, I'll prepare an example of that solution. In the meantime, you can try to experiment with it by yourself.

Regards,
Piotr

@Rainer-Lang
Copy link

@pwittchen I'm also interested in an example of your lib combined with retrofit.

@pwittchen
Copy link
Owner

@kdani41 @Rainer-Lang I was quite busy, so I haven't published it yet. Sorry for a long delay. I'm also working on a few updates in this project. I'll try to publish this sample ASAP and then notify you in the comments in this issue.

@pwittchen
Copy link
Owner

I've added simple examples with nested calling with OkHttp and Retrofit here:
https://github.com/pwittchen/ReactiveNetwork#integration-with-other-libraries

If you're using other libraries, they can be integrated in the similar manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants