Method ForEach
ForEach<TSource>(IAsyncEnumerable<TSource>, Action<TSource>, CancellationToken)
Immediately executes the given action on each element in the source sequence.
Declaration
public static ValueTask ForEach<TSource>(this IAsyncEnumerable<TSource> source, Action<TSource> action, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<TSource> | source | The sequence of elements |
| Action<TSource> | action | The action to execute on each element |
| CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
| Type | Description |
|---|---|
| ValueTask |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements in the sequence |
Remarks
This operator executes immediately.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ForEach<TSource>(IAsyncEnumerable<TSource>, Func<TSource, ValueTask>, CancellationToken)
Immediately executes the given action on each element in the source sequence.
Declaration
public static ValueTask ForEach<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask> action, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<TSource> | source | The sequence of elements |
| Func<TSource, ValueTask> | action | The action to execute on each element |
| CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
| Type | Description |
|---|---|
| ValueTask |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements in the sequence |
Remarks
This operator executes immediately.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ForEach<TSource>(IAsyncEnumerable<TSource>, Action<TSource, int>, CancellationToken)
Immediately executes the given action on each element in the source sequence. Each element's index is used in the logic of the action.
Declaration
public static ValueTask ForEach<TSource>(this IAsyncEnumerable<TSource> source, Action<TSource, int> action, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<TSource> | source | The sequence of elements |
| Action<TSource, int> | action | The action to execute on each element; the second parameter of the action represents the index of the source element. |
| CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
| Type | Description |
|---|---|
| ValueTask |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements in the sequence |
Remarks
This operator executes immediately.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ForEach<TSource>(IAsyncEnumerable<TSource>, Func<TSource, int, ValueTask>, CancellationToken)
Immediately executes the given action on each element in the source sequence. Each element's index is used in the logic of the action.
Declaration
public static ValueTask ForEach<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask> action, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<TSource> | source | The sequence of elements |
| Func<TSource, int, ValueTask> | action | The action to execute on each element; the second parameter of the action represents the index of the source element. |
| CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
| Type | Description |
|---|---|
| ValueTask |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements in the sequence |
Remarks
This operator executes immediately.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|