-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Provide factories for creating the default scheduler instances. #3856
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
Conversation
Please correct me if I'm wrong but looks like as soon as you access one of the new methods,
Just wanted to say for those who may find this PR later: empty/non-empty state of schedulers is not 100% source of truth for ui tests, you may have some background or time related (periodic/etc) code that does not affect the ui directly and may even freeze tests. |
You are accessing the methods from the hook which was called from the static initializer of this class on first reference to |
Yup, but there is still potential problem if somebody will try to create schedulers using these methods outside of the hook, for example in Maybe move these methods to |
That prevents package scoped methods from being used in the factory. |
We can move schedulers to Ideal solution would be to return schedulers in // sorry, I'm very tired and want to sleep, so I may come to wrong conclusions. |
*/ | ||
@Deprecated | ||
public final class NewThreadScheduler extends Scheduler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to just delete this type. It was public
yes, but it was final
, had a private constructor, instance()
was package scoped, and Schedulers.newThread()
was never guaranteed to return instance of it. This basically made it completely unusable from application code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
to that, we can just mention that in changelog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but not sure when the delete could happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine for even patch release, NewThreadScheduler
has no public fields nor methods + private constructor. Without reflection or unchecked casting it's unusable for users.
I vote for removing it right in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it's relatively safe to remove now (even with a patch release).
The factories were moved to the hook. |
👍 |
👍 now, but let me ask again, what about this:
No need for new methods, no need to fight with instantiation order and package scope visibility. Yes, user won't be able to instantiate new scheduler of required type outside of the hook, but it's not possible at the moment, so nobody loses nothing. |
👍 |
Unlike other hooks, the
RxJavaSchedulersHook
has no access to the realScheduler
instances in order to do wrapping/delegation. With these factory methods, a hook can access what would otherwise be the instance used since there is often no other means of creating these specialized schedulers.For Android this wrapping/delegation use-case is important for UI testing. We have a means to tell the testing framework when the app is idle and to do that we need to hook into the schedulers to know when they're empty. This is easy to do currently, but you cannot wrap the real instance and instead have to supply alternate implementations which might subtly alter the behavior under test.
These three methods are referenced in #3724, and I think providing the defaults is useful as well as eventually adding overloads which take
ThreadFactory
instances for each.