Skip to content

Ensure awaitFrame() only awaits a single frame when used from the main thread #3431

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

Closed
wants to merge 1 commit into from

Conversation

pablobaxter
Copy link
Contributor

@pablobaxter pablobaxter commented Sep 2, 2022

Fix to resolve #3432

return suspendCancellableCoroutine { cont ->
Dispatchers.Main.dispatch(EmptyCoroutineContext, Runnable {
if (Looper.myLooper() === Looper.getMainLooper()) { // Check if we are already in the main looper thread
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I'm not yet convinced this should be the solution though.
I would expect that Dispatchers.Main.immediate would be enough, but it is not due to our implementation details.

We'll fix it in the next release, but it is an open question whether we are going to use this particular approach though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No probs!

The only reason I took the Looper approach here is because this code is specific to Android, and I didn't see anything similar for JavaFX or Swing implementations (awaitPulse() was the closest parallel). I see no problems and I am not opposed to using Dispatchers.Main.immediate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be the way though!

I've opened #3437 with a few changes on top of yours that I'll squash into your commit. Thanks for the contribution, we'll merge it in the next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First use of awaitFrame() awaits extra draw frame when used with Main dispatcher
2 participants