-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.x: Surprising scheduler behaviour #6696
Comments
|
Do you mean |
Replace |
Using For me this looks awkward — as a user I would like to observe on a specified scheduler in sequential order. Currently it seems to violate Law of least surprise. How do you think? Or maybe current implementation has some obvious performance advantage that I am unaware of? |
Reactive concurrency is complicated and scheduling is an orthogonal concept (when vs. where), hence a perfectly sequential scheduler used with an operator can result in non-intuitive event signaling pattern downstream. Also your type of lockstepping and coordination is rare. |
Is this well described somewhere so I could study the topic a bit more?
Should this be mentioned somewhere? It looks like an important gotcha.
I use this approach to relief the calling thread as quickly as possible since it is bound to native code and prone to break the underlying system that I do not control (here modelled as the |
See my blog and the operator writing guide.
The |
Having several observers on a specific, single threaded scheduler and several subsequent emissions from another thread the scheduler distributes events sequentially between observers. The non-intuitive part is that it first distributes all events to the first observer, then all events to the second and so on… This may end up with observers being notified about events in a wrong order. See ReactiveX/RxJava#6696
A helper question — do you know why schedulers are designed this way by default (instead of being basically equivalent to |
Scheduler is an abstraction over crossing an asynchronous boundary by providing methods to run work somewhere. It doesn't know what or how much work it means. |
I think this topic is cleared and appropriate Javadoc change has landed so I am closing. Thank you very much for the help. I do have some other questions about surface'ing reactive and non-reactive world.
I would like to discuss those matters or find a way to learn on how to deal with them. Should I create separate issues or...? |
|
|
) Having several observers on a specific, single threaded scheduler and several subsequent emissions from another thread the scheduler distributes events sequentially between observers. The non-intuitive part is that it first distributes all events to the first observer, then all events to the second and so on… This may end up with observers being notified about events in a wrong order. See ReactiveX/RxJava#6696
Brief description
Given a shared upstream and two flows using
.observeOn()
before.filter()
may change the original emission order.RxJava Version
2.2.13
Code sample
Actual (surprising) result
Expected result
Notes
Schedulers.from(Executors.newSingleThreadExecutor())
— I thought that somehow the executors may be optimised in a way that batches individual runnables and cycles them before cycling the queue of observers. I foundSchedulers.single()
which states (emphasis mine):.observeOn()
calling viascheduleDirect
yields expected results:Question
Is the actual result an expected one?
If so — could you explain why? Is it possible to alter the flow without reordering operators and achieve expected results?
The text was updated successfully, but these errors were encountered: