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.

2.x: Single.flatMapObservable does not respect observeOn

See original GitHub issue

RxJava version 2.1.2.

The following code:

Single.just("Test")
      .subscribeOn(Schedulers.computation())
      .flatMapObservable(
            s -> {
                System.out.println("1: " + Thread.currentThread());

                return Observable.just(1)
                      .observeOn(Schedulers.io())
                      //.doOnNext(o -> System.out.println("2: " + Thread.currentThread()))
                 ;
            }
      )
      .subscribe(o -> {
          System.out.println("3: " + Thread.currentThread());
      });

…produces the following output:

1: Thread[RxComputationThreadPool-1,5,main]
3: Thread[RxComputationThreadPool-1,5,main]

Expected output here is:

1: Thread[RxComputationThreadPool-1,5,main]
3: Thread[RxCachedThreadScheduler-1,5,main]

However, when the line containing doOnNext is uncommented, this is the output:

1: Thread[RxComputationThreadPool-1,5,main]
2: Thread[RxCachedThreadScheduler-1,5,main]
3: Thread[RxCachedThreadScheduler-1,5,main]

It looks like the thread is not switched in the first case.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (18 by maintainers)

github_iconTop GitHub Comments

3reactions
JakeWhartoncommented, Aug 15, 2017

If you bind data, delaying a frame will cause a noticeable UI problem.

2reactions
akarnokdcommented, Aug 14, 2017

Especially on Android, this behavior may lead to crashes if the value is not emitted on the main thread

That’s why peoply, by reflex, apply .observeOn(AndroidSchedulers.mainThread()) to route the results back to the main thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Single (RxJava Javadoc 2.2.13)
Like Observable , a running Single can be stopped through the Disposable instance provided to consumers through SingleObserver.onSubscribe(io.reactivex.
Read more >
Single (RxJava Javadoc 3.1.5) - ReactiveX
The Single class implements the Reactive Pattern for a single value response. Single behaves similarly to Observable except that it can only emit...
Read more >
Understanding RxJava subscribeOn and observeOn
flatMap() wraps each item being emitted by an Observable letting you apply its own RxJava operators including assigning a new Scheduler using ...
Read more >
Why doesn't my RxJava Flowable respect backpressure when ...
You don't need it because Flowable.fromIterable (and by the way, RxJava has a range operator) supports and honors backpressure.
Read more >
目录 - Gitee
How does this relate to RxJava itself? RxJava 1.x. RxJava 2.x. Public APIs of Libraries. Pros of Exposing Reactive Stream APIs instead of...
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