-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support yield in immediate dispatchers #1667
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
696837f
to
ab79214
Compare
ab79214
to
8a64aa7
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.
Thanks!
@JakeWharton Note, that if somebody creates a wrapper around
Then |
The first thing I reached for was |
The other potential problematic case would be coroutine running without a dispatcher at all (a truly unconfined coroutine). The existing and updated version of
|
@JakeWharton I gave a bit more thought to the second idea. It is not really good. The change in this PR (support However, it is not surprising if some code that uses a remote-call library like retrofit without a dispatcher gets resumed in another thread. So, the first option to work around
UPDATE: Corrected to use You'd use just like you use
|
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.
Well done, please squash before merging
d89abe6
to
1b492bf
Compare
So yield now checks for "Unconfined" dispatcher instead of "isDispatchNeeded" and works properly for immediate dispatchers. Fixes #1474
1b492bf
to
6743801
Compare
I've found a problem with this change. We try to dispatch to dispatchers that return As a fix, The downside of this change is that a few extra objects are created on each Please, review. |
See ImmediateYieldTest.testWrappedUnconfinedDispatcherYieldStackOverflow This commit changes the way Unconfined dispatcher is detected. Instead of equality check we try to dispatch to the dispatcher with a specially updated coroutine context that has YieldContext element that is processed by the Unconfied dispatcher in a special way.
b6b5136
to
2808f09
Compare
Also, as it was before, throw UnsupportedOperationException from the Dispatcher.Unconfined.dispatch method in case some code wraps the Unconfined dispatcher but fails to delegate isDispatchNeeded properly.
2808f09
to
22fe6c7
Compare
Fixes #1474