Table of Contents

Class Concurrent

Namespace
ReactiveUI.Extensions.Async.Subjects
Assembly
ReactiveUI.Extensions.dll

Provides helper methods for forwarding asynchronous observer notifications concurrently to multiple observers.

public static class Concurrent
Inheritance
Concurrent

Remarks

The methods in this class are intended for scenarios where multiple asynchronous observers need to be notified in parallel. All observer notifications are dispatched concurrently, and the returned ValueTask completes when all observer operations have finished. If the observers collection is empty, the methods complete immediately. Exceptions thrown by individual observers are aggregated into a single exception, consistent with Task.WhenAll behavior.

Methods

ForwardOnCompletedConcurrently<T>(IReadOnlyList<IObserverAsync<T>>, Result)

Invokes the OnCompletedAsync method on each observer in the collection concurrently, forwarding the specified result to all observers.

public static ValueTask ForwardOnCompletedConcurrently<T>(IReadOnlyList<IObserverAsync<T>> observers, Result result)

Parameters

observers IReadOnlyList<IObserverAsync<T>>

A read-only list of observers to which the completion notification will be forwarded. Cannot be null.

result Result

The result to pass to each observer's OnCompletedAsync method.

Returns

ValueTask

A ValueTask that represents the asynchronous operation of notifying all observers. The task completes when all observers have finished processing the completion notification. If the observers list is empty, a default ValueTask is returned.

Type Parameters

T

The type of the elements observed by the observers.

Remarks

All observers are notified concurrently. The returned ValueTask completes when all OnCompletedAsync operations have finished. If any observer throws an exception, the returned task will complete with an AggregateException containing all exceptions thrown.

ForwardOnErrorResumeConcurrently<T>(IReadOnlyList<IObserverAsync<T>>, Exception, CancellationToken)

Forwards an error notification to all specified asynchronous observers concurrently, allowing each observer to handle the error and resume as appropriate.

public static ValueTask ForwardOnErrorResumeConcurrently<T>(IReadOnlyList<IObserverAsync<T>> observers, Exception error, CancellationToken cancellationToken)

Parameters

observers IReadOnlyList<IObserverAsync<T>>

A read-only list of asynchronous observers to which the error notification will be forwarded. Cannot be null.

error Exception

The exception representing the error to forward to each observer. Cannot be null.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the forwarding operation.

Returns

ValueTask

A ValueTask that represents the asynchronous operation of forwarding the error to all observers. The task completes when all observers have processed the error notification.

Type Parameters

T

The type of the elements observed by the observers.

Remarks

If the list of observers is empty, the method returns a default ValueTask and no notifications are sent. Each observer receives the error notification concurrently. If cancellation is requested via the cancellation token, the operation may be canceled before completion.

ForwardOnNextConcurrently<T>(IReadOnlyList<IObserverAsync<T>>, T, CancellationToken)

Forwards the specified value to all observers concurrently by invoking their OnNextAsync methods.

public static ValueTask ForwardOnNextConcurrently<T>(IReadOnlyList<IObserverAsync<T>> observers, T value, CancellationToken cancellationToken)

Parameters

observers IReadOnlyList<IObserverAsync<T>>

A read-only list of observers that will receive the value. Cannot be null.

value T

The value to forward to each observer.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the forwarding operation.

Returns

ValueTask

A ValueTask that represents the asynchronous operation of forwarding the value to all observers. The task completes when all observers have processed the value.

Type Parameters

T

The type of the value to forward to the observers.

Remarks

If the observers list is empty, the returned ValueTask is already completed. All OnNextAsync calls are started concurrently; exceptions from observers are aggregated in the returned task.