These are chat archives for ReactiveX/RxJava

5th
Dec 2018
Aditya Chaturvedi
@apexkid
Dec 05 2018 13:57
Hello guys. Greetings. I need some help from the Rx community here. I am new to Rx and using RxJava to write an Android app. I want to chain the response from a GET api returning a Single to a POST api returning a Completable. I am not able to achieve that. I posted a SO question but no help till now. Please suggest how to do this. https://stackoverflow.com/questions/53633071/how-to-pass-output-of-a-single-to-a-completable-in-rxjava
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:02
Did you resolve problem?
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:02
No
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:05
I am not really know what do you want . Basically, you get the Single<String> then want to send this String to api2 for posrting api ?
Is that right ?
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:05
Correct
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:05
Okay
Firstly,You have to get a String
api.getToken().blockingGet()
It will returning the String for you
Next,
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:07
I can do single.subscribe( r -> completableAPi(r).subscribe ... ) but the code will be messy. I want to chain operations the way i mentioned in the SO
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:07
pass the value to post api
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:07
This is android so cannot do blocking calls.
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:07
You can
api2.saveToken(token = {api1.getToken().blockingget})
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:08
ok let me try this
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:09
Using lambda in this case
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:13
Not working. The subscription itself is not getting triggered.
completableAPI(singleAPI.blockingGet()).subscribeOn(..).observeOn(..).subcribe(...)
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:15
wait
Aditya Chaturvedi
@apexkid
Dec 05 2018 14:18
When i do singleAPI.map(result -> completableAPI(result) it returns me a Single<Completable>. My usecase is that i just want to return a Completable on which i can subscribe.
If i do Completable.fromSingle(...single<completable> here...) then it the completable call is ignored.
and if i do singleAPi.flatmapCompletable(result -> completableAPI(result)), I am able to get an object of type Completable but the inner call happens on the main thread even if i do subscribeOn(Schedulers.io()).
Too many things that i am confused with here.
hayaticakici
@hayaticakici
Dec 05 2018 14:42
test
Vu Minh Hoang
@vuminhhoang
Dec 05 2018 14:44
still there ?
I just tried
it worked !
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:08
@vuminhhoang Can you share code snippet on gist?
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:10
OMG hehe please try not to block and never ever subribe inside a subscription :astonished:
As you said, you can chain the calls, for example using flatMap
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:11
@ibaca Sounds weird to be as well. Whats the point of Rx if we have to block. :|
That's true but i am not able to translate the Single<Completable> to Completable
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:12
What is the single and what is the Completable?
In the app domain (ex a user get and a archive post)
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:12
@ibaca Will it be possible to take a look at the stackoverflow link i shared? I have written in detail there. You will get entire context of the problem
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:13
Oh hehe OK
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:13
Thanks! :)
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:16
uhm but you have already solved the chain problem
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:16
It is not working.
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:16
yep, this is another problem, try to add the .subscribeOn(io()) in the save observable too
it depends on how those methods are implemented (getToken and saveTokenToBackend)
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:24
both methods are Retrofit api call
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:25
and the RxThreadCallAdapter should not handle this for you?
are you configured that correctly?
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:26
yes its working when i call it individually
but not when i chain it
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:27
then just repeat the subscribeOn just after the api call
Aditya Chaturvedi
@apexkid
Dec 05 2018 16:27
brb
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:27
look like the API call apply the observeOn automattically (I think, not sure…)
Ignacio Baca Moreno-Torres
@ibaca
Dec 05 2018 16:33
uhm RxJava2CallAdapterFactory do not do that, not sure, anyways your problem MUST be that the flatMap has been evaluated on the mainThread so adding the subscribeOn must solve the problem, also, I really think that you should apply the RxJava2CallAdapterFactory using the RxJava2CallAdapterFactory.createWithScheduler(io()) call, that assert that all request call are evaluated in the io scheduler
Aditya Chaturvedi
@apexkid
Dec 05 2018 19:32
Thanks @ibaca . Your suggestion of changing the RxFactory worked. I still wonder why the issue was happening in the first place.
I was already going .ObserveOn to my completable