These are chat archives for ReactiveX/RxJava

12th
Jun 2016
dangxunb
@dangxunb
Jun 12 2016 15:26
Hello, I have a question, do I need to check observable's terminal/intermediate operation like Java 8's Stream API?
Dorus
@Dorus
Jun 12 2016 15:27
All operators are Intermediate in Rx. Except Subscribe.
I'm not even sure if we call Subscribe an operator.
dangxunb
@dangxunb
Jun 12 2016 15:29
oh thanks you
The Javadoc of Observable's subscribe method said that: "Subscribes to an Observable and provides a callback to handle the items it emits."
It makes me confused alot because I don't understand where are observers??
Kartikay Dani
@kdani41
Jun 12 2016 15:41

Hi all, I have this small question regarding rx

I have this simple retrofit2 api interface which contains

    interface Api {
        @GET(BuildConfig.END_POINT) Observable<Response> fetchData();
    }

So everything is fine when I'm doing a fresh request but let say I fire a request and I un-subscribe immediately or if the request is fired in the background (and no one is there to listen) and then I try to fire new request it returns nothing.

So, in code it looks something like this:

in Activity::onPause I perform un-subscription and in Activity::onResume I fire the request again.

My request looks something like this::

    api.fetchData()
        .timeout(30,TimeUnit.SECONDS)
        .doOnNext(new Action1<Response>() {
            @Override public void call(Response response) {
                list = response.getDataForList();
            }
        }).flatMap(new Func1<Response, Observable<List<Object>>>() {
            @Override public Observable<Object>> call(Response response) {
                return Observable.just(list);
            }
        });

When I tried debugging it, the call is made but doOnNext() is not called. None of the lifecycle methods are called.

And just for clarification from here I'm just returning the observable which I'm using it somewhere else where I'm observing on main thread and subscribing on IO.

I don't know if I doing something wrong in rx or if it's a retrofit issue. Any help or suggestions will be appreciated. Thanks for your time 👍

Dorus
@Dorus
Jun 12 2016 15:51
@dangxunb The callbacks in the Subscribe method make up the observer.
you could see it as Observable.subscribe(observer) and observer {onNext: { ... }, onCompleted {...}, onError {...}}, so you call Observable.subscribe((next) -> {...}, (error) -> {...}, () -> { ... completed ...} )
dangxunb
@dangxunb
Jun 12 2016 15:53
very clear, thanks you so much!
dangxunb
@dangxunb
Jun 12 2016 20:14
Does BehaviorSubject internally use a computational scheduler?
Ben Christensen
@benjchristensen
Jun 12 2016 20:17
No.
Subjects have no scheduling.
dangxunb
@dangxunb
Jun 12 2016 20:19
I checked it by print the name of the Thread in the subscription's callback block. It said: RxComputationScheduler-1. I don't specify any subscribeOn() Scheduler
Oh excuse me, my fault. I missed the sample() operation. Very sorry :worried: