-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Use DirectExecutor for Task.addOnCompleteListener #2992
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
2406793
to
d17314e
Compare
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.
Good catch.
Though a lot of tests fail with java.lang.NoClassDefFoundError: android/os/Handler
as some parts of the stub library still use TaskExecutors.MAIN_THREAD
, e.g. TaskCompletionSource(token)
constructor, please address that (probably by returning FakeAndroid
back)
d17314e
to
3e94722
Compare
Ah, yep I can reproduce locally after a clean build, not sure how those passed for me before. I added |
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.
Thanks!
Curious when the next release will be cut that includes this change. I have a feeling |
The current version of
Task.addOnCompleteListener
that is being used schedules the listener to run on the main thread. Because we are completing aDeferred
or canceling or resuming a continuation, the listener can be run on any thread and therefore we don't need to introduce an unnecessary hop to the main thread if the rest of the work is happening on other threads.Implementation notes:
MoreExecutors.directExecutor
exists, but I implemented it directly since it is an extremely simple implementation and that avoids introducing any dependency.Because we no longer touch the main thread in tests, I was able to remove the
FakeAndroid
file that was faking theHandler
andLooper
This fixes #2990