Class SerialDisposableAsync
- Namespace
- ReactiveUI.Extensions.Async.Disposables
- Assembly
- ReactiveUI.Extensions.dll
Provides a thread-safe mechanism for managing a single asynchronously disposable resource that can be replaced or disposed of serially.
public class SerialDisposableAsync : IAsyncDisposable
- Inheritance
-
SerialDisposableAsync
- Implements
- Extension Methods
Remarks
When a new disposable is set using SetDisposableAsync, the previously held disposable (if any) is asynchronously disposed. Disposing the SerialDisposableAsync instance disposes the current disposable and prevents further disposables from being set. This class is useful for scenarios where a resource needs to be replaced or updated over time, ensuring that only one resource is active and properly disposed of at any given moment. All operations are safe to use concurrently from multiple threads.
Constructors
SerialDisposableAsync()
public SerialDisposableAsync()
Methods
DisposeAsync()
Asynchronously releases the resources used by the object.
public ValueTask DisposeAsync()
Returns
- ValueTask
A ValueTask that represents the asynchronous dispose operation. The task will be completed when all resources have been released.
Remarks
Subsequent calls to this method after disposal will have no effect. This method is safe to call multiple times.
SetDisposableAsync(IAsyncDisposable?)
Replaces the currently tracked asynchronous disposable resource with a new one, disposing the previous resource if present.
public ValueTask SetDisposableAsync(IAsyncDisposable? value)
Parameters
valueIAsyncDisposableThe new IAsyncDisposable instance to track. Can be null to clear the current resource.
Returns
- ValueTask
A ValueTask that represents the asynchronous dispose operation of the previously tracked resource, or of
valueif the object has already been disposed. If there is no resource to dispose, the returned task is already completed.
Remarks
If the object has already been disposed, value is disposed immediately.
Otherwise, the previously tracked resource, if any, is disposed asynchronously. This method is
thread-safe.