Skip to content

Commit 4fb6f64

Browse files
committed
add normative text for async cancellation
1 parent 2832342 commit 4fb6f64

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

standard/classes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5479,6 +5479,8 @@ An iterator block may occur as a *method_body*, *operator_body* or *accessor_bod
54795479

54805480
When a function member or local function is implemented using an iterator block, it is a compile-time error for the parameter list of the function member to specify any `in`, `out`, or `ref` parameters, or an parameter of a `ref struct` type.
54815481

5482+
An asynchronous iterator can support cancellation of the asynchronous operation. One parameter must be of the type `System.Threading.Tasks.CancellationToken` and be marked with the `System.Runtime.CompilerServices.EnumeratorCancellation` attribute (§enumerator-cancellation). When an asynchronous iterator has such a parameter, that `CancellationToken` is passed to `GetAsyncEnumerator`, and the enumerator's `MoveNextAsync` method.
5483+
54825484
### 15.15.2 Enumerator interfaces
54835485

54845486
The ***enumerator interfaces*** are the non-generic interface `System.Collections.IEnumerator` and all instantiations of the generic interfaces `System.Collections.Generic.IEnumerator<T>`.
@@ -5532,6 +5534,8 @@ The `MoveNext` and `MoveNextAsync` methods of an enumerator object encapsulates
55325534

55335535
`MoveNext` returns a `bool` value whose meaning is described below. `MoveNextAsync` returns a `ValueTask<bool>` ([§15.14.3](classes.md#15143-evaluation-of-a-task-returning-async-function)). The result value of the task returned from `MoveNextAsync` has the same meaning as the result value from `MoveNext`. In the following description, the actions described for `MoveNext` apply to `MoveNextAsync` with the following difference: Where stated that `MoveNext` returns `true` or `false`, `MoveNextAsync` sets its task to the *completed* state, and sets the task’s result value to the corresponding `true` or `false` value.
55345536

5537+
The `MoveNextAsync` method includes an optional `CancellationToken` parameter. The argument is the token marked with the `EnumeratorCancellation` attribute of the iterator (§15.15.1).
5538+
55355539
The precise action performed by `MoveNext` or `MoveNextAsync` depends on the state of the enumerator object when invoked:
55365540

55375541
- If the state of the enumerator object is **before**, invoking `MoveNext`:
@@ -5608,4 +5612,4 @@ An enumerable object may implement more interfaces than those specified above.
56085612

56095613
An enumerable object provides an implementation of the `GetEnumerator` methods of the `IEnumerable` and `IEnumerable<T>` interfaces. The two `GetEnumerator` methods share a common implementation that acquires and returns an available enumerator object. The enumerator object is initialized with the argument values and instance value saved when the enumerable object was initialized, but otherwise the enumerator object functions as described in [§15.15.5](classes.md#15155-enumerator-objects).
56105614

5611-
An asynchronous enumerable object provides an implementation of the `GetAsyncEnumerator` method of the `IAsyncEnumerable<T>` interface. This method returns an available asynchronous enumerator object. The enumerator object is initialized with the argument values and instance value saved when the enumerable object was initialized, but otherwise the enumerator object functions as described in [§15.15.5](classes.md#15155-enumerator-objects).
5615+
An asynchronous enumerable object provides an implementation of the `GetAsyncEnumerator` method of the `IAsyncEnumerable<T>` interface. This method returns an available asynchronous enumerator object. The enumerator object is initialized with the argument values and instance value saved when the enumerable object was initialized, including the optional cancellation token, but otherwise the enumerator object functions as described in [§15.15.5](classes.md#15155-enumerator-objects).

0 commit comments

Comments
 (0)