DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.12.1" />

 Scope

Represents a collection of callbacks to be executed at the end of the lexical scope.
public void Defer(Action callback)

Attaches callback to this lexical scope.

public void Defer(Func<ValueTask> callback)

Attaches callback to this lexical scope.

public void Dispose()

Executes all attached callbacks synchronously.

Executes all attached callbacks asynchronously.

public void RegisterForDispose(IDisposable disposable)

Registers an object for disposal.

public void RegisterForDisposeAsync(IAsyncDisposable disposable)

Registers an object for asynchronous disposal.