Skip to content

Commit e2fd4cf

Browse files
committed
Grammar and formatting
Replace "async method" with "async function" This feature applies to local functions and lambda expressions as well. Put examples in an informative *Example* block Update cross references as needed
1 parent 776ac49 commit e2fd4cf

1 file changed

Lines changed: 55 additions & 53 deletions

File tree

standard/classes.md

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5872,77 +5872,79 @@ If the return type of the async function is `void`, evaluation differs from the
58725872

58735873
This allows the context to keep track of how many `void`-returning async functions are running under it, and to decide how to propagate exceptions coming out of them.
58745874

5875-
Rather than using a task builder type based on the *return_type* of an async method, the attribute `AsyncMethodBuilder` can be applied to that method to indicate a different task builder type.
5875+
Rather than using a task builder type based on the *return_type* of an async function, the attribute `AsyncMethodBuilder` can be applied to that async function to indicate a different task builder type.
58765876

58775877
It is an error to apply this attribute to a lambda with an implicit return type.
58785878

58795879
The ability to provide an alternate builder type shall not be used when the synthesized entry-point for top-level statements is async (§7.1.3). For that, an explicit entry-point is needed.
58805880

5881-
When an async method is compiled, the builder type is determined by:
5881+
When an async function is compiled, the builder type is determined by:
58825882

58835883
1. Using the builder type from the `AsyncMethodBuilder` attribute, if one is present;
5884-
1. Otherwise, falling back to the builder type determined by the method's *return_type*.
5884+
1. Otherwise, falling back to the builder type determined by the async function's *return_type* (§15.14.2).
58855885

58865886
If an `AsyncMethodBuilder` attribute is present, the builder type specified by that attribute is constructed, if necessary.
58875887

5888-
If the override type is an open generic type, take the single type argument of the async method's return type and substitute it into the override type.
5888+
If the override type is an open generic type, take the single type argument of the async function's return type and substitute it into the override type.
58895889

58905890
If the override type is a bound generic type, then an error results.
58915891

5892-
If the async method's return type does not have a single type argument, an error results.
5892+
If the async function's return type does not have a single type argument, an error results.
58935893

5894-
To verify that the builder type is compatible with *return_type* of the async method:
5894+
To verify that the builder type is compatible with *return_type* of the async function:
58955895

58965896
1. Look for the public `Create` method with no type parameters and no parameters on the constructed builder type. It is an error if the method is not found, or if the method returns a type other than the constructed builder type.
58975897
1. Look for the public `Task` property. It is an error if the property is not found.
5898-
1. Consider the type of that `Task` property (a task-like type). It is an error if the task-like type does not match the *return_type* of the async method. (It is not necessary for *return_type* to be a task-like type.)
5898+
1. Consider the type of that `Task` property (a task-like type). It is an error if the task-like type does not match the *return_type* of the async function. (It is not necessary for *return_type* to be a task-like type.)
58995899

5900-
Consider the following code fragment:
5901-
5902-
```csharp
5903-
public async ValueTask<T> ExampleAsync() { … }
5904-
```
5905-
5906-
This will be compiled to something like the following:
5907-
5908-
```csharp
5909-
[AsyncStateMachine(typeof(<ExampleAsync>d__29))]
5910-
[CompilerGenerated]
5911-
static ValueTask<int> ExampleAsync()
5912-
{
5913-
<ExampleAsync>d__29 stateMachine;
5914-
stateMachine.<>t__builder
5915-
= AsyncValueTaskMethodBuilder<int>.Create();
5916-
stateMachine.<>1__state = -1;
5917-
stateMachine.<>t__builder.Start(ref stateMachine);
5918-
return stateMachine.<>t__builder.Task;
5919-
}
5920-
```
5921-
5922-
However, the following code fragment:
5923-
5924-
```csharp
5925-
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
5926-
static async ValueTask<int> ExampleAsync() { … }
5927-
```
5928-
5929-
in which the attribute `AsyncMethodBuilder` is applied to that method, would instead be compiled to something like:
5930-
5931-
```csharp
5932-
[AsyncStateMachine(typeof(<ExampleAsync>d__29))]
5933-
[CompilerGenerated]
5934-
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
5935-
static ValueTask<int> ExampleAsync()
5936-
{
5937-
<ExampleAsync>d__29 stateMachine;
5938-
stateMachine.<>t__builder
5939-
= PoolingAsyncValueTaskMethodBuilder<int>.Create();
5940-
// <>t__builder now a different type
5941-
stateMachine.<>1__state = -1;
5942-
stateMachine.<>t__builder.Start(ref stateMachine);
5943-
return stateMachine.<>t__builder.Task;
5944-
}
5945-
```
5900+
> *Example*: Consider the following code fragment:
5901+
>
5902+
> ```csharp
5903+
> public async ValueTask<int> ExampleAsync() { … }
5904+
> ```
5905+
>
5906+
> This will be compiled to something like the following:
5907+
>
5908+
> ```csharp
5909+
> [AsyncStateMachine(typeof(<ExampleAsync>d__29))]
5910+
> [CompilerGenerated]
5911+
> static ValueTask<int> ExampleAsync()
5912+
> {
5913+
> <ExampleAsync>d__29 stateMachine;
5914+
> stateMachine.<>t__builder
5915+
> = AsyncValueTaskMethodBuilder<int>.Create();
5916+
> stateMachine.<>1__state = -1;
5917+
> stateMachine.<>t__builder.Start(ref stateMachine);
5918+
> return stateMachine.<>t__builder.Task;
5919+
> }
5920+
> ```
5921+
>
5922+
> However, the following code fragment:
5923+
>
5924+
> ```csharp
5925+
> [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
5926+
> static async ValueTask<int> ExampleAsync() { … }
5927+
> ```
5928+
>
5929+
> in which the attribute `AsyncMethodBuilder` is applied to that async function, would instead be compiled to something like:
5930+
>
5931+
> ```csharp
5932+
> [AsyncStateMachine(typeof(<ExampleAsync>d__29))]
5933+
> [CompilerGenerated]
5934+
> [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
5935+
> static ValueTask<int> ExampleAsync()
5936+
> {
5937+
> <ExampleAsync>d__29 stateMachine;
5938+
> stateMachine.<>t__builder
5939+
> = PoolingAsyncValueTaskMethodBuilder<int>.Create();
5940+
> // <>t__builder now a different type
5941+
> stateMachine.<>1__state = -1;
5942+
> stateMachine.<>t__builder.Start(ref stateMachine);
5943+
> return stateMachine.<>t__builder.Task;
5944+
> }
5945+
> ```
5946+
>
5947+
> *end example*
59465948

59475949
## 15.15 Synchronous and asynchronous iterators
59485950

0 commit comments

Comments
 (0)