-
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
Is passing Schedulers around best practice, a last resort or something in between? #3915
Comments
Can't say that it's "best practice" or something, but in order to reduce amount of boilerplate ceremonies and number of parameters in the constructor we follow next practice: class SomeViewModel { // Presenter/whatever, you got it.
@Inject @TimeScheduler
Scheduler timeScheduler;
@Inject @IoScheduler
Scheduler ioScheduler;
SomeViewModel(ObjectGraph graph) {
graph.inject(this);
}
} Then in tests we just pass test implementation of the // Finally got rid of using Schedulers hook in our test suite today because we saw some shared state problems, really happy about it. Also in case if you're interested, looks like that we've finally found a good solution for dealing with
Nothing published yet because (I need some free time + try it in real life project), but you can track discussion/progress here. |
I'm closing this issue due to inactivity. If you have further input on the issue, don't hesitate to reopen this issue or post a new one. |
@DavidMihola as promised, finished solution regarding passing around RxAndroid's main thread scheduler: RxUi, feedback is welcomed! |
@artem-zinnatullin How do you achieve |
@artem-zinnatullin Nevermind, custom Qualifiers I assume http://docs.oracle.com/javaee/7/api/javax/inject/Qualifier.html |
Yup!
…On Mon, Jun 12, 2017, 13:22 Alan Evans ***@***.***> wrote:
@artem-zinnatullin <https://github.com/artem-zinnatullin> Nevermind,
custom Qualifiers I assume
http://docs.oracle.com/javaee/7/api/javax/inject/Qualifier.html
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3915 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA7B3H70UVU0vxzcScGtEBhlhhCGE4P0ks5sDRFlgaJpZM4IY_X->
.
|
This question is a follow-up to @artem-zinnatullin's comment to my question from yesterday.
For years now I've been using the static methods like
Schedulers.io()
andAndroidSchedulers.mainThread()
to move my Observables around. Since I've started to write more tests I've also been trying to mostly move allsubscribeOn
s andobserveOn
s as far "to the ends" as possible:subscribeOn
immediately after the Observables I get from Retrofit andobserveOn
immediately before any View related stuff.This kept all the intermediate layers Scheduler agnostic and worked quite well except for two points:
computation()
by default - this is a problem for testing where I would like to useTestScheduler
to be able to use "virtual time".replay()
seems to replay on the main thread by default - this just cost me three hours, because other parts of the app relied on areplay
ed Observable to also be onio()
.So, both cases could be solved by putting a few
subscribeOn
s in several places of my code, and passing Schedulers explicitly tointerval()
, etc.In these cases, especially with regards to testing, is it best practice to mostly pass Schedulers around explicitly or is that seen as a last resort to be used when the default Schedulers fail or are inappropriate?
As always, thanks for any advice!
The text was updated successfully, but these errors were encountered: