ActionAsyncDisposable Class

Implements both IAsyncDisposable and IDisposable by invoking a given callback upon disposal.

public class ActionAsyncDisposable : IAsyncDisposable, IDisposable
Implements

Constructors

NameDescription
ActionAsyncDisposable(Func<ValueTask>)Initializes a new instance of the ActionAsyncDisposable class.

ActionAsyncDisposable(Func<ValueTask>)

Initializes a new instance of the ActionAsyncDisposable class.

public ActionAsyncDisposable(Func<ValueTask> onDisposeAsync)

Parameters

onDisposeAsync Func<ValueTask>
A callback to invoke upon the first call to ActionAsyncDisposable.Dispose or ActionAsyncDisposable.DisposeAsync.

Exceptions

ArgumentNullException
onDisposeAsync is null.

See also

Methods

NameDescription
Dispose()When invoked for the first time, invokes the callback passed to the constructor and synchronously awaits its result. If / when invoked again, or if invoked after ActionAsyncDisposable.DisposeAsync, this method does nothing.
DisposeAsync()When invoked for the first time, invokes the callback passed to the constructor. If / when invoked again, or if invoked after ActionAsyncDisposable.Dispose, this method does nothing.

Dispose()

When invoked for the first time, invokes the callback passed to the constructor and synchronously awaits its result.

If / when invoked again, or if invoked after ActionAsyncDisposable.DisposeAsync, this method does nothing.

public void Dispose()

DisposeAsync()

When invoked for the first time, invokes the callback passed to the constructor.

If / when invoked again, or if invoked after ActionAsyncDisposable.Dispose, this method does nothing.

public ValueTask DisposeAsync()

Returns

ValueTask A ValueTask that represents the ongoing operation.