question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OnSubscribeRange with AsyncOnSubscribe does not work without backpressure

See original GitHub issue

Hi, im trying to implement observable with backpressure. i’ve investigated a bit and came with this solution:

    @Test
    public void testObservable() throws Exception {

        Observable<Integer> observable = Observable.create(new AsyncOnSubscribe<Void, Integer>() {

            @Override
            protected Void generateState() {
                return null;
            }

            @Override
            protected Void next(Void state,
                                long requested,
                                Observer<Observable<? extends Integer>> observer) {
                observer.onNext(Observable.create(
                        new OnSubscribeRange(0, Integer.MAX_VALUE -1)));
                return null;
            }
        });
        observable
//              .observeOn(Schedulers.computation())
//              .subscribeOn(Schedulers.io())
                .subscribe(d -> System.out.println(">>>>>>"));

        sleep(10000);
    }

I’ve found out that AsyncOnSubscribe provides basics for back pressure support and im using the OnSubscribeRange to n times call some method(via chained map operator)

The problem is that it seems its very unreliable in initialization. It works if i do the backpressure in subscriber(request(n)) but once i try to go without backpressure it does not work. Data is emitted but does not reach the subscriber. I believe its being accumulated in rx.observables.AsyncOnSubscribe.AsyncOuterManager#subscribeBufferToObservable endlessly. As if the subscribe was not noticed.

Am i doing something wrong? I understand that the AsyncOnSubscribe is experimental, so if there is any recommended way how to implement backpressure support correctly please point me to the right direction.

Currently we are using rxjava 1.1.2 NOTE: I understand that the OnSubscribeRange supports only max int values so i implemented OnSubscribeLongRange but the same behaviour applies for both.

Thank you in advance, Viliam

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
stealthcodecommented, Mar 30, 2016

A more concise way to write this would be to use the static initializer on SynOnSubscribe.createStateless(…)

On Wed, Mar 30, 2016, 07:03 Witko notifications@github.com wrote:

Hi, thank you for your suggestions. I’ve ended up with:

observable = Observable.create(new SyncOnSubscribe<Object, Data>() {

        @Override
        protected Void generateState() {
            return null;
        }

        @Override
        protected Object next(Object state, Observer<? super Data> observer) {
            observer.onNext(nextData());
            return null;
        }
    });

This seems to work just fine. Thanks again!

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/ReactiveX/RxJava/issues/3793#issuecomment-203446582

0reactions
Witkocommented, Mar 30, 2016

Thanks! even nicer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reactive Programming with RxJava - manualzz
Subscribers can propagate their demand and request only as many items as they can process by using a feedback channel known as backpressure....
Read more >
rx.Observable Maven / Gradle / Ivy - Download JAR files
Backpressure : *: The operator honors backpressure and generates values on-demand (when requested). *; Scheduler: *: {@code create} does not operate by ...
Read more >
Reactive Programming with RxJava - Library
“This book is a deep dive into the concepts and uses of RxJava in particular, and reactive programming in general, by authors who...
Read more >
Reactive Programming with R xjava - PDF Free Download
2. 3 Praise for Reactive Programming with RxJava This book is a deep dive into the concepts and uses of RxJava in particular,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found