Class BaseReplayLatestSubjectAsync<T>
- Namespace
- ReactiveUI.Extensions.Async.Subjects
- Assembly
- ReactiveUI.Extensions.dll
Provides a base implementation for an asynchronous subject that replays the latest value to new subscribers and supports asynchronous notification of observers.
public abstract class BaseReplayLatestSubjectAsync<T> : ObservableAsync<T>, ISubjectAsync<T>, IObserverAsync<T>, IAsyncDisposable, IObservableAsync<T>
Type Parameters
TThe type of the elements processed by the subject.
- Inheritance
-
BaseReplayLatestSubjectAsync<T>
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
This abstract class is intended to be inherited by types that implement custom replay and notification logic for asynchronous observers. When a new observer subscribes, it immediately receives the latest value if one is available. The subject supports asynchronous notification of values, errors, and completion, and ensures thread-safe access for concurrent operations.
Constructors
BaseReplayLatestSubjectAsync(Optional<T>)
Provides a base implementation for an asynchronous subject that replays the latest value to new subscribers and supports asynchronous notification of observers.
protected BaseReplayLatestSubjectAsync(Optional<T> startValue)
Parameters
startValueOptional<T>An optional initial value to be emitted to new subscribers before any other values are published.
Remarks
This abstract class is intended to be inherited by types that implement custom replay and notification logic for asynchronous observers. When a new observer subscribes, it immediately receives the latest value if one is available. The subject supports asynchronous notification of values, errors, and completion, and ensures thread-safe access for concurrent operations.
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 registered observers that the asynchronous operation has completed and provides the final result.
public ValueTask OnCompletedAsync(Result result)
Parameters
resultResultThe result to deliver to observers upon completion. Cannot be null.
Returns
- ValueTask
A ValueTask that represents the asynchronous notification operation. The task completes when all observers have been notified.
Remarks
Subsequent calls after the first completion will have no effect. This method is thread-safe and ensures that observers are notified only once.
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
observersIReadOnlyList<IObserverAsync<T>>A read-only list of observers to be notified of the completion event. Cannot be null.
resultResultThe 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 according to the completion semantics of the operation. Exceptions thrown during notification may affect the completion of the returned task.
OnErrorResumeAsync(Exception, CancellationToken)
Notifies all observers of an error and resumes asynchronous processing as appropriate.
public ValueTask OnErrorResumeAsync(Exception error, CancellationToken cancellationToken)
Parameters
errorExceptionThe exception that occurred and will be sent to observers. Cannot be null.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the notification operation.
Returns
- ValueTask
A task that represents the asynchronous notification operation.
Remarks
If the result has already been set, this method returns immediately without notifying observers. Observers are notified asynchronously.
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
observersIReadOnlyList<IObserverAsync<T>>A read-only list of observers to notify or resume after the error. Cannot be null.
errorExceptionThe exception that triggered the error handling logic. Cannot be null.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask
A ValueTask that represents the asynchronous error recovery operation.
Remarks
Override this method to implement custom error recovery logic for asynchronous observers. The method is called when an error occurs and provides an opportunity to resume or redirect processing for the affected observers.
OnNextAsync(T, CancellationToken)
Asynchronously notifies all subscribed observers with the specified value.
public ValueTask OnNextAsync(T value, CancellationToken cancellationToken)
Parameters
valueTThe value to send to each observer.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the notification operation.
Returns
- ValueTask
A task that represents the asynchronous notification operation.
Remarks
If the sequence has already completed, this method does not notify observers.
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
observersIReadOnlyList<IObserverAsync<T>>A read-only list of observers to be notified. Cannot be null.
valueTThe value to send to each observer.
cancellationTokenCancellationTokenA 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
observerIObserverAsync<T>The asynchronous observer that will receive notifications. Cannot be null.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the subscription operation.
Returns
- ValueTask<IAsyncDisposable>
A disposable object that can be used to unsubscribe the observer from the sequence. If the sequence has already completed, returns an empty disposable.
Remarks
If the sequence has already completed, the observer will immediately receive the completion notification and will not be added to the list of active observers. If a last value is available, it is pushed to the observer upon subscription.