-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
API Proposal: ExecutionContext.Restore(ExecutionContext? executionContext) #38011
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
Related change in ASP.NET that would make use of this api dotnet/aspnetcore#23175 |
@stephentoub are you happy for this to be for review? |
@kouvel, any concerns with this being exposed? |
Was a naming question raised #37942 (comment)
|
Either seems fine to me. |
Looks fine to me. I was also wondering if it should be prefixed with |
@stephentoub @kouvel This is marked as 6.0. If we were to approve this this week, would it still make sense for 5.0? |
Would mean the upstream change in aspnet core could be merged for 5.0 dotnet/aspnetcore#23175 /cc @davidfowl |
Yes |
Looks good as proposed. namespace System.Threading
{
public sealed class ExecutionContext
{
public static void Restore(ExecutionContext? executionContext);
}
} |
Background and Motivation
Alternative to the approved api #30867 "ExecutionContext.Run ref overloads"
await
ing aTask
returning method that is itself notasync
does not guarantee undoingAsyncLocal
/ExecutionContext
changes (as it is the responsibility of the callee)ExecutionContext
does provide an callback based method that acts as a stack:However using it to just undo changes is clunky (involves rearranging code into a callback); as well as applying the current context to run on, when its already on the current context.
It also doesn't provide a return value; and if it was guarding multiple
await
s arranging to return a singleTask
(via using state as a reference) becomes complicated.Rather than using it in a stack based "apply=>undo" manner; it would be useful if it could be restored directly inline.
Related ASP.NET issues dotnet/aspnetcore#15384, dotnet/aspnetcore#13991
Proposed API
Usage Examples
Alternative Designs
#30867 "ExecutionContext.Run ref overloads"; this again requires contorting the code to the callback based pattern and is problematic for multiple awaits as regular
.Run
as well as introducing a large method that has generic code expansion.Also guard the multiple
await
s behind an explicitlyasync
method:However this introduces an extra statemachine per request and an additional allocation per request; as well as causing the ExecutionContext to be captured and restored per request; when really we just want to capture it at the start of request processing and only restore/reset it per request.
/cc @davidfowl @stephentoub
The text was updated successfully, but these errors were encountered: