-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Task.Yield() is missing a .ConfigureAwait(bool) option #23498
Comments
@AArnott do you have a specific API in mind? |
Semantically it feels a bit wrong to me. In my mind, |
Yes, and that's exactly what we switched to using this week when we needed this.
Because it's where users expect to find it. Most users of await have never used or seen the
To me, I always think of the I don't think most await users appreciate the difference between awaitable types like So my argument is that since CoreFx doesn't offer a way to force a yield and resume off the caller's context, and we believe that requirement is a valid one, we should add the API to fill the gap in the place our existing users would expect to find it. And IMO that would be by configuring the awaitable they are already using.
Yes: public struct YieldAwaitable
{
public ConfiguredYieldAwaitable ConfigureAwait(bool continueOnCapturedContext);
} Or an equivalent extension method as we've defined in vs-threading. |
All good thoughts, but functionally it's a dup of https://github.com/dotnet/corefx/issues/15490. If we ever moved forward on enabling that functionality, either API could be considered. Thanks. |
As there are legitimate uses of
Task.Yield()
and legit uses ofTask.ConfigureAwait(false)
, it's odd that there is no API to allowawait Task.Yield().ConfigureAwait(false);
. Anyone who must yield back to the caller but does not want to resume on the caller'sSynchronizationContext
has no convenient API to enable that.In vs-threading we just filled this gap ourselves, but it seems like a worthwhile addition to .NET itself.
See also: https://stackoverflow.com/questions/28309185/task-yield-in-library-needs-configurewaitfalse
Proposal
Or an equivalent extension method as we've defined in vs-threading.
The text was updated successfully, but these errors were encountered: