-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Android: await frame #1474
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
Comments
This is not a regression. It never worked this way after #737. The improvement that we did in #737 was to support yielding into the "unconfined" virtual event loop that is being created for things like Can you, please, go into a little bit more detail of what is your use-cases? Why would you need to be able to use |
My Android code looks like this: viewCreatedScope.launch {
// Suspends until the predraw listener fires just before rendering a frame
view.awaitPreDraw()
prepareViewForAnimation()
// This is needed because we need to finish rendering the frame we just set up
// before starting the animation. Ideally this would be a `yield()` instead.
delay(1)
TransitionManager.beginDelayedTransition(view)
moveViewsToEndState()
} It would also be nice to let other things on the main thread run. |
Frankly, I don't think that |
That might be. But posting on a main handler will definitely allow the rendering to complete as it will happen when returning from the pre draw listener. |
That's only true when the message sent to the handler is waiting for vsync (aka a frame). Coroutines dispatchers wrapped around handlers by default will set the async flag on the message which will not wait for a frame. |
This caught me when updating my
|
This change is breaking Retrofit's mitigation against exceptions that are thrown synchronously which relies on |
Uh. Oh. We'll see what we can do. |
As special internal fun CoroutineDispatcher.isDispatchSupported is introduced to speical-case Unconfined dispatcher that cannot be dispatched to. All other dispatcher return `true`. This gives a little more freedom in distinguishing dispatchers | isDispNeeded | isDispSupported Regular | true | true Immediate | depends | true Unconfined | false | false So yield now checks for "isDispatchNeeded" and works properly for immediate dispatchers. Fixes #1474
As special internal fun CoroutineDispatcher.isDispatchSupported is introduced to special-case Unconfined dispatcher that cannot be dispatched to. All other dispatcher return `true`. This gives a little more freedom in distinguishing dispatchers | isDispNeeded | isDispSupported Regular | true | true Immediate | depends | true Unconfined | false | false So yield now checks for "isDispatchSupported" and works properly for immediate dispatchers. Fixes #1474
As special internal fun CoroutineDispatcher.isDispatchSupported is introduced to special-case Unconfined dispatcher that cannot be dispatched to. All other dispatcher return `true`. This gives a little more freedom in distinguishing dispatchers | isDispNeeded | isDispSupported Regular | true | true Immediate | depends | true Unconfined | false | false So yield now checks for "isDispatchSupported" and works properly for immediate dispatchers. Fixes #1474
So yield now checks for "Unconfined" dispatcher instead of "isDispatchNeeded" and works properly for immediate dispatchers. Fixes #1474
So yield now checks for "Unconfined" dispatcher instead of "isDispatchNeeded" and works properly for immediate dispatchers. Fixes #1474
@keyboardr Be aware that this issue still exists if you yield inside a |
It seems like #737 might have regressed, yielding on the immediate main dispatcher while on the main thread is currently a no-op as shown by this example:
The example above is placed inside the
Application.onCreate
which is already running on the main thread.The expected output would be:
But the actual output is:
The text was updated successfully, but these errors were encountered: