<PackageReference Include="Nito.Disposables" Version="2.3.0-pre02" />

Nito.Disposables.SingleNonblockingAsyncDisposable<T>

A base class for disposables that need exactly-once semantics in a thread-safe way.
public bool IsDisposed { get; }

Whether this instance has been disposed (or is being disposed).

protected SingleNonblockingAsyncDisposable(T context)

Creates a disposable for the specified context.

protected abstract ValueTask DisposeAsync(T context)

The actual disposal method, called only once from DisposeAsync.

Disposes this instance.

protected bool TryUpdateContext(Func<T, T> contextUpdater)

Attempts to update the stored context. This method returns false if this instance has already been disposed (or is being disposed).