Skip to content

Improve "Async return types" docs #47289

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

xakep139
Copy link
Contributor

@xakep139 xakep139 commented Jul 11, 2025

Summary

This PR rephrases a misleading statement regarding an awaiter type - an AsyncMethodBuilderAttribute should be applied on a type that an async method returns, not on a type that GetAwaiter() method returns.

The same requirement is showcased in the spec - https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#15141-general.

As an example:

async CustomTask SomeMethodAsync() { /* ... */ }

// The attribute should be applied here:
[AsyncMethodBuilder(typeof(CustomAsyncMethodBuilder))]
class CustomTask
{
    public CustomAwaiter GetAwaiter() { /* ... */ }
}

class CustomAwaiter : INotifyCompletion
{
    public void OnCompleted(Action continuation) { /* ... */ }
}

internal class CustomAsyncMethodBuilder
{
    // The builder must implement a bunch of methods like (only a few required are listed):
    public static CustomAsyncMethodBuilder Create() { /* ... */ }
    public void SetException(Exception exception) { /* ... */ }
    public void SetResult() { /* ... */ }
    public CustomTask Task { get; }
}

Rigth now the documentation states that an AsyncMethodBuilderAttribute should be applied on a CustomAwaiter type from the example above, which is misleading.


Internal previews

📄 File 🔗 Preview link
docs/csharp/asynchronous-programming/async-return-types.md Async return types (C#)

@xakep139 xakep139 requested review from BillWagner and a team as code owners July 11, 2025 08:38
@dotnetrepoman dotnetrepoman bot added this to the July 2025 milestone Jul 11, 2025
@dotnet-policy-service dotnet-policy-service bot added dotnet-csharp/svc async-task-programming/subsvc community-contribution Indicates PR is created by someone from the .NET community. labels Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async-task-programming/subsvc community-contribution Indicates PR is created by someone from the .NET community. dotnet-csharp/svc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant