Table of Contents

Class BaseStatelessReplayLastSubjectAsync<T>

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

Provides a base class for stateless, asynchronous subjects that replay the last value to new subscribers and support resuming after errors or completion. Designed for scenarios where observers may join at any time and should receive the most recent value, if available.

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

Type Parameters

T

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

Inheritance
BaseStatelessReplayLastSubjectAsync<T>
Implements
Derived
Inherited Members
Extension Methods

Remarks

This abstract class implements asynchronous observer and observable patterns, allowing derived classes to define custom notification, error handling, and completion behaviors. It manages observer subscriptions and ensures that the most recent value (if any) is replayed to new subscribers. Thread safety is provided for concurrent access and notification. Typical use cases include event streaming, stateful data flows, or scenarios where late subscribers should receive the latest state.

Constructors

BaseStatelessReplayLastSubjectAsync(Optional<T>)

Provides a base class for stateless, asynchronous subjects that replay the last value to new subscribers and support resuming after errors or completion. Designed for scenarios where observers may join at any time and should receive the most recent value, if available.

protected BaseStatelessReplayLastSubjectAsync(Optional<T> startValue)

Parameters

startValue Optional<T>

The optional initial value to be used as the starting point for the subject. If provided, this value is immediately available to new subscribers until a new value is published.

Remarks

This abstract class implements asynchronous observer and observable patterns, allowing derived classes to define custom notification, error handling, and completion behaviors. It manages observer subscriptions and ensures that the most recent value (if any) is replayed to new subscribers. Thread safety is provided for concurrent access and notification. Typical use cases include event streaming, stateful data flows, or scenarios where late subscribers should receive the latest state.

Methods

DisposeAsync()

Asynchronously releases the unmanaged resources used by the object.

public ValueTask DisposeAsync()

Returns

ValueTask

A ValueTask that represents the asynchronous dispose operation.

OnCompletedAsync(Result)

Notifies all observers that the asynchronous operation has completed and performs necessary cleanup.

public ValueTask OnCompletedAsync(Result result)

Parameters

result Result

The result information to be provided to observers upon completion.

Returns

ValueTask

A task that represents the asynchronous notification operation.

Remarks

After this method is called, the list of observers is cleared and the internal state is reset. Subsequent calls to this method will have no effect on previously completed observers.

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

Invoked to asynchronously notify all observers that the sequence has completed, providing the final result.

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

Parameters

observers IReadOnlyList<IObserverAsync<T>>

The collection of observers to be notified of the sequence completion. Cannot be null.

result Result

The result to provide to observers upon completion. Represents the outcome of the observed sequence.

Returns

ValueTask

A ValueTask that represents the asynchronous notification operation.

Remarks

This method is called when the observed sequence has finished processing. Implementations should ensure that all observers are notified according to the completion semantics of the sequence. This method is intended to be overridden in derived classes to customize completion behavior.

OnErrorResumeAsync(Exception, CancellationToken)

Handles an error by notifying all observers asynchronously and allows the operation to resume without propagating the exception.

public ValueTask OnErrorResumeAsync(Exception error, CancellationToken cancellationToken)

Parameters

error Exception

The exception that occurred and will be reported to observers. Cannot be null.

cancellationToken CancellationToken

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

Returns

ValueTask

A task that represents the asynchronous error notification operation.

Remarks

This method ensures that all registered observers are notified of the specified error. The operation completes when all observers have been notified or the cancellation is requested.

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

Handles an error by resuming asynchronous observation for the specified observers.

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

Parameters

observers IReadOnlyList<IObserverAsync<T>>

A read-only list of observers to notify or resume after the error occurs. Cannot be null.

error Exception

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

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous error handling operation.

Remarks

Implementations should ensure that error handling is performed in a way that allows observers to continue receiving notifications or to recover from the error, as appropriate. This method is intended to be overridden to provide custom error recovery strategies in asynchronous observer scenarios.

OnNextAsync(T, CancellationToken)

Asynchronously notifies all registered 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 task that represents the asynchronous notification operation.

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

Asynchronously notifies the specified observers of a new 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 deliver 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.

Remarks

Derived classes should implement this method to define how notifications are delivered to observers. The method should honor the provided cancellation token and ensure that all observers in the list are notified according to the desired semantics.

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 task that represents the asynchronous operation. The result contains a disposable object that can be used to unsubscribe the observer.

Remarks

If the observable has a current value, it is immediately sent to the observer upon subscription. Disposing the returned object will unsubscribe the observer and may reset the observable's state if there are no remaining subscribers.