Skip to content
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]: AsyncContext for cancellation and ConfigureAwait #102111

Open
alrz opened this issue May 11, 2024 · 1 comment
Open

[API Proposal]: AsyncContext for cancellation and ConfigureAwait #102111

alrz opened this issue May 11, 2024 · 1 comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading.Tasks untriaged New issue has not been triaged by the area owner

Comments

@alrz
Copy link
Member

alrz commented May 11, 2024

Background and motivation

To avoid passing cancellation and ConfigureAwait in every callsite, there's room to use async local to propagate the value for all the subsequent call sites.

API Proposal

Extracted from #94620 (comment)

public static class AsyncContext {
  public static void PushConfigureAwait(bool capture);
  public static void PushCancellationToken(CancellationToken token);
  public static bool ContinueOnCapturedContext { get; }
  public static CancellationToken CancellationToken { get; }
  public static void PushContext<T>(T context); // possibly a user-defined context
  public static T GetContext<T>();
}

Popping the value would be done internally.

API Usage

AsyncContext.PushConfigreAwait(false); // calling at the start of the program would make all tasks to not capture the context.

Alternative Designs

No response

Risks

No response

@alrz alrz added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label May 11, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 11, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 11, 2024
@huoyaoyuan huoyaoyuan added area-System.Threading.Tasks and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 11, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-threading-tasks
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading.Tasks untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants