These are chat archives for ReactiveX/RxJava

8th
May 2017
Vladimir Baryshnikov
@vovkab
May 08 2017 18:35
Question, if I do request(1) in onStart() but don't call it again in onNext will it wait until I do, or it still will just emit items?
David Karnok
@akarnokd
May 08 2017 19:42
You have to keep calling request(1) because otherwise no data will be sent to your Subscriber.
Vladimir Baryshnikov
@vovkab
May 08 2017 19:53
Any idea why n is changing from 1 to 9223372036854775807 after flatmap?
Vladimir Baryshnikov
@vovkab
May 08 2017 20:01
Adding maxConcurrent = 1 helps a bit , but I think it still emits multiple requests, while I only requested 1. It doesn't wait for request(n) call
Vladimir Baryshnikov
@vovkab
May 08 2017 20:15

Here is repro example:

Observable.range(1, 10)
        .doOnNext(integer -> System.out.println("doOnNext, Integer: " + integer))

        .doOnRequest(n -> System.out.println("doOnRequest, before flatmap n: " + n))
        .flatMap(integer -> Observable.just(String.valueOf(integer)), 1)
        .doOnRequest(n -> System.out.println("doOnRequest, after flatmap n: " + n))

        .subscribeOn(Schedulers.io())
        .observeOn(Schedulers.immediate())
        .subscribe(new Subscriber<String>() {
            @Override public void onStart() {
                super.onStart();
                System.out.println("onStart");
                request(1);
            }

            @Override public void onCompleted() {
                System.out.println("onCompleted");
            }

            @Override public void onError(Throwable e) {
                System.out.println("onError " + e);
            }

            @Override public void onNext(String s) {
                System.out.println("onNext: '" + s + "'");
                // request(1);
            }
        });

Result:

onStart
doOnRequest, after flatmap n: 1
doOnRequest, before flatmap n: 1
doOnNext, Integer: 1
onNext: '1'
doOnRequest, before flatmap n: 1
doOnNext, Integer: 2
Is there a way to prevent flatmap from doing anything until subscriber actually ask for it?
Vladimir Baryshnikov
@vovkab
May 08 2017 21:41
@akarnokd do you know what else I can do, if any, to avoid undesirable calls?