Skip to content

,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)

View source

Summary: Asynchronously invokes the specified action for each element in the sequence as elements are received.

Type parameters

NameDescription
TThe type of elements in the sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
onNextAsyncFuncA 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

NameDescription
TThe type of elements in the sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
onNextAsyncFuncA 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.
cancellationTokenCancellationTokenA 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)

View source

Summary: Asynchronously invokes the specified action for each element in the sequence as elements are received.

Type parameters

NameDescription
TThe type of elements in the sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
onNextActionThe 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

TypeCondition
System.ArgumentNullExceptionThrown 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

NameDescription
TThe type of elements in the sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
onNextActionThe action to invoke for each element in the sequence. Cannot be null.
cancellationTokenCancellationTokenA 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

TypeCondition
System.ArgumentNullExceptionThrown if onNext is null.