Table of Contents

Class BaseStatelessSubjectAsync<T>

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

Provides a base class for implementing asynchronous, stateless subjects that broadcast notifications to multiple observers. Supports asynchronous notification, error handling, and completion signaling for observers subscribing to the subject.

public abstract class BaseStatelessSubjectAsync<T> : ObservableAsync<T>, ISubjectAsync<T>, IObserverAsync<T>, IAsyncDisposable, IObservableAsync<T>

Type Parameters

T

The type of the elements processed and broadcast by the subject.

Inheritance
BaseStatelessSubjectAsync<T>
Implements
Derived
Inherited Members
Extension Methods

Remarks

This abstract class enables the creation of custom asynchronous subjects that do not maintain internal state between notifications. It manages observer subscriptions and provides extensibility points for handling value notifications, error recovery, and completion events. Implementations should override the core notification methods to define specific broadcasting or error-handling behaviors. Thread safety and observer management are handled by the base class, allowing derived classes to focus on notification logic.

Constructors

BaseStatelessSubjectAsync()

protected BaseStatelessSubjectAsync()

Methods

DisposeAsync()

Asynchronously releases resources used by the current instance.

public ValueTask DisposeAsync()

Returns

ValueTask

A ValueTask that represents the asynchronous dispose operation.

Remarks

After calling this method, the instance should not be used. This method is intended to be called when the object is no longer needed, to ensure that all resources are properly released.

OnCompletedAsync(Result)

Notifies all registered observers that the operation has completed and provides the final result asynchronously.

public ValueTask OnCompletedAsync(Result result)

Parameters

result Result

The result to deliver to observers upon completion. Cannot be null.

Returns

ValueTask

A ValueTask that represents the asynchronous notification operation.

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

Invoked to asynchronously notify all observers of the completion event with the specified result.

protected abstract ValueTask OnCompletedAsyncCore(IReadOnlyList<IObserverAsync<T>> observers, Result result)

Parameters

observers IReadOnlyList<IObserverAsync<T>>

The collection of observers to be notified. Cannot be null.

result Result

The result to provide to each observer upon completion.

Returns

ValueTask

A ValueTask that represents the asynchronous notification operation.

Remarks

Implementations should ensure that all observers are notified, and handle any exceptions according to the desired notification semantics.

OnErrorResumeAsync(Exception, CancellationToken)

Handles an error by resuming the asynchronous operation, allowing observers to continue receiving notifications despite the specified exception.

public ValueTask OnErrorResumeAsync(Exception error, CancellationToken cancellationToken)

Parameters

error Exception

The exception that caused the error condition. Cannot be null.

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous resume operation.

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

Handles error recovery for the specified observers by resuming asynchronous processing after an error occurs.

protected abstract ValueTask OnErrorResumeAsyncCore(IReadOnlyList<IObserverAsync<T>> observers, Exception error, CancellationToken cancellationToken)

Parameters

observers IReadOnlyList<IObserverAsync<T>>

A read-only list of observers that should resume processing after the error. Cannot be null.

error Exception

The exception that triggered the error recovery logic. Cannot be null.

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous error recovery operation.

Remarks

Implementations should ensure that observers are notified or resumed appropriately based on the error. This method is intended to be called when an error occurs during asynchronous observation, allowing custom error handling strategies.

OnNextAsync(T, CancellationToken)

Asynchronously notifies all subscribed observers of a new value.

public ValueTask OnNextAsync(T value, CancellationToken cancellationToken)

Parameters

value T

The value to send to each observer.

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous notification operation.

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

Asynchronously notifies the specified observers with the provided value.

protected abstract ValueTask OnNextAsyncCore(IReadOnlyList<IObserverAsync<T>> observers, T value, CancellationToken cancellationToken)

Parameters

observers IReadOnlyList<IObserverAsync<T>>

A read-only list of observers to be notified. Cannot be null.

value T

The value to send to each observer.

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous notification operation.

SubscribeAsyncCore(IObserverAsync<T>, CancellationToken)

Subscribes the specified asynchronous observer to receive notifications from the observable sequence.

protected override ValueTask<IAsyncDisposable> SubscribeAsyncCore(IObserverAsync<T> observer, CancellationToken cancellationToken)

Parameters

observer IObserverAsync<T>

The asynchronous observer that will receive notifications. Cannot be null.

cancellationToken CancellationToken

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

Returns

ValueTask<IAsyncDisposable>

A value task that represents the asynchronous subscription operation. The result is an IAsyncDisposable that can be disposed to unsubscribe the observer.

Remarks

Disposing the returned IAsyncDisposable will remove the observer from the subscription list. The subscription is established immediately upon calling this method.