-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Send async messages to the Android main looper #577
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
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.
LGTM, although I wonder why you didn't raise the compileSdk to 28 to avoid reflection and expose new APIs.
It's a jar, not an aar |
Is this a problem regarding the SDK used to compile it? |
Yes as it does not use AGP |
@@ -40,7 +42,32 @@ public fun Handler.asCoroutineDispatcher(): HandlerDispatcher = | |||
|
|||
private const val MAX_DELAY = Long.MAX_VALUE / 2 // cannot delay for too long on Android | |||
|
|||
private val mainHandler = Handler(Looper.getMainLooper()) | |||
private val mainHandler = Looper.getMainLooper().asHandler(async = true) |
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.
Shouldn't we provide system property to opt-out this behaviour?
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.
Hmm... maybe. It's a challenging situation because disabling this makes the entire app slower where you might just want to change the behavior for a single coroutine.
It may be worth discussing providing a dispatcher that is always async=false
to the main thread so that decisions can be made on a coroutine-by-coroutine basis rather than globally to the whole app.
I worry about the case when someone has a problem, disables async to "fix" it, and then that starts getting cargo culted around slowing down everyone's apps.
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 point.
Let's wait for the feedback from the users and will discuss solutions for their particular problems.
This PR carries enough value to release it as is.
Rebased onto develop. |
Closes #427