,System.Func{--0,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask})} ,System.Func{--0,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask},System.Threading.CancellationToken)} ,System.Action{--0})} ,System.Action{--0},System.Threading.CancellationToken)}
ObservableAsync.ForEachAsync(IObservableAsync, Func) method¶
Defined in
Type: ObservableAsync
Namespace: ReactiveUI.Extensions.Async
Assembly: ReactiveUI.Extensions.dll
Applies to
net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481
Overloads¶
- 1.
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask> onNextAsync) - 2.
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask> onNextAsync, CancellationToken cancellationToken) - 3.
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Action<T> onNext) - 4.
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Action<T> onNext, CancellationToken cancellationToken)
1. Overload¶
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask> onNextAsync)
Summary: Asynchronously invokes the specified action for each element in the sequence as elements are received.
Type parameters
| Name | Description |
|---|---|
T | The type of elements in the sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
this | [IObservableAsync | The source observable sequence. |
onNextAsync | Func | A function to invoke for each element in the sequence. The function receives the element and a cancellation token, and returns a ValueTask that completes when processing is finished. |
Returns: ValueTask -- A ValueTask that represents the asynchronous operation. The task completes when all elements have been processed or the operation is canceled.
Remarks
If the sequence completes or is canceled, the method returns when all in-flight actions have finished. Exceptions thrown by the action or during enumeration will propagate to the returned task.
2. Overload¶
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask> onNextAsync, CancellationToken cancellationToken)
Summary: Asynchronously invokes the specified action for each element in the sequence as elements are received.
Type parameters
| Name | Description |
|---|---|
T | The type of elements in the sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
this | [IObservableAsync | The source observable sequence. |
onNextAsync | Func | A function to invoke for each element in the sequence. The function receives the element and a cancellation token, and returns a ValueTask that completes when processing is finished. |
cancellationToken | CancellationToken | A token to observe while waiting for the sequence to complete. The operation is canceled if the token is signaled. |
Returns: ValueTask -- A ValueTask that represents the asynchronous operation. The task completes when all elements have been processed or the operation is canceled.
Remarks
If the sequence completes or is canceled, the method returns when all in-flight actions have finished. Exceptions thrown by the action or during enumeration will propagate to the returned task.
3. Overload¶
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Action<T> onNext)
Summary: Asynchronously invokes the specified action for each element in the sequence as elements are received.
Type parameters
| Name | Description |
|---|---|
T | The type of elements in the sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
this | [IObservableAsync | The source observable sequence. |
onNext | Action | The action to invoke for each element in the sequence. Cannot be null. |
Returns: ValueTask -- A task that represents the asynchronous iteration operation. The task completes when the sequence has been fully processed or the operation is canceled.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown if onNext is null. |
4. Overload¶
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Action<T> onNext, CancellationToken cancellationToken)
Summary: Asynchronously invokes the specified action for each element in the sequence as elements are received.
Type parameters
| Name | Description |
|---|---|
T | The type of elements in the sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
this | [IObservableAsync | The source observable sequence. |
onNext | Action | The action to invoke for each element in the sequence. Cannot be null. |
cancellationToken | CancellationToken | A cancellation token that can be used to cancel the iteration. |
Returns: ValueTask -- A task that represents the asynchronous iteration operation. The task completes when the sequence has been fully processed or the operation is canceled.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown if onNext is null. |