Table of Contents

Class ObserverAsync<T>

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

Represents an asynchronous observer that processes notifications of type T using asynchronous methods.

public abstract class ObserverAsync<T> : IObserverAsync<T>, IAsyncDisposable

Type Parameters

T

The type of the elements received by the observer.

Inheritance
ObserverAsync<T>
Implements
Extension Methods

Remarks

Implement this abstract class to handle asynchronous event streams or push-based data sources, where notifications may arrive concurrently or in rapid succession. The observer provides asynchronous methods for handling new data, errors, and completion signals, and supports proper resource cleanup via asynchronous disposal. Instances are not thread-safe for concurrent notification handling; notifications are processed sequentially, and reentrant calls are detected and reported as unhandled exceptions.

Constructors

ObserverAsync()

protected ObserverAsync()

Methods

DisposeAsync()

Asynchronously releases the resources used by the object.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

Remarks

Call this method to clean up resources when the object is no longer needed. This method is safe to call multiple times; subsequent calls after disposal will have no effect. Any unhandled exceptions that occur during disposal are captured and reported but do not prevent the completion of the dispose operation.

DisposeAsyncCore()

Performs application-defined tasks associated with asynchronously releasing unmanaged resources.

protected virtual ValueTask DisposeAsyncCore()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

Remarks

Override this method to provide custom asynchronous resource cleanup logic in a derived class. This method is called by DisposeAsync to perform the actual resource release. The default implementation does nothing and returns a completed task.

OnCompletedAsync(Result)

Asynchronously performs completion logic when the operation has finished, handling any finalization or cleanup tasks required.

public ValueTask OnCompletedAsync(Result result)

Parameters

result Result

The result of the completed operation, containing information about its outcome.

Returns

ValueTask

A task that represents the asynchronous completion operation.

Remarks

If an unhandled exception occurs during completion, it is passed to the unhandled exception handler. This method ensures that necessary resources are released after completion.

OnCompletedAsyncCore(Result)

Performs asynchronous completion logic when the operation has finished processing the specified result.

protected abstract ValueTask OnCompletedAsyncCore(Result result)

Parameters

result Result

The result of the operation to be processed during completion.

Returns

ValueTask

A ValueTask that represents the asynchronous completion operation.

OnErrorResumeAsync(Exception, CancellationToken)

Handles an error by attempting to resume processing asynchronously.

public ValueTask OnErrorResumeAsync(Exception error, CancellationToken cancellationToken)

Parameters

error Exception

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

cancellationToken CancellationToken

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

Returns

ValueTask

A task that represents the asynchronous error handling operation.

OnErrorResumeAsyncCore(Exception, CancellationToken)

Handles an error by providing an asynchronous mechanism to resume execution after an exception occurs.

protected abstract ValueTask OnErrorResumeAsyncCore(Exception error, CancellationToken cancellationToken)

Parameters

error Exception

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

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous operation of resuming execution after the error.

Remarks

Override this method to implement custom error recovery or resumption logic in derived classes. The method is called when an error occurs and allows the operation to continue or perform cleanup asynchronously.

OnNextAsync(T, CancellationToken)

Asynchronously processes the next value in the sequence.

public ValueTask OnNextAsync(T value, CancellationToken cancellationToken)

Parameters

value T

The value to be processed.

cancellationToken CancellationToken

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

Returns

ValueTask

A task that represents the asynchronous operation.

OnNextAsyncCore(T, CancellationToken)

Processes the next value in the asynchronous sequence.

protected abstract ValueTask OnNextAsyncCore(T value, CancellationToken cancellationToken)

Parameters

value T

The value to be processed.

cancellationToken CancellationToken

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

Returns

ValueTask

A ValueTask that represents the asynchronous operation.