Skip to content

disposable

Disposable utilities for using / await using declarations.

Class Description
AsyncCallbackDisposable An async disposable that executes a callback when disposed via await using (or a manual await disposable[Symbol.asyncDispose]()).
AsyncDisposableBase Abstract base for an AsyncDisposableEx: it carries the re-dispose guard (via MultipleDisposeBehavior) and the AsyncDisposableEx.asyncDispose alias; a subclass only implements AsyncDisposableBase.performDisposeAsync.
CallbackDisposable A disposable that executes a callback when disposed.
CombineAsyncDisposable An AsyncDisposableEx that combines multiple async disposables and disposes all of them when it is disposed.
CombineDisposable A DisposableEx that combines multiple disposables and disposes all of them when it is disposed.
DisposableBase Abstract base for a DisposableEx: it carries the re-dispose guard (via MultipleDisposeBehavior) and the DisposableEx.dispose alias; a subclass only implements DisposableBase.performDispose.
Interface Description
AsyncCallbackDisposableConstructorParams The parameters for constructing an AsyncCallbackDisposable.
AsyncDisposableEx An AsyncDisposable that additionally exposes a convenience AsyncDisposableEx.asyncDispose method, so a stored handle can be disposed as handle.asyncDispose() instead of the clunkier handle[Symbol.asyncDispose]().
CallbackDisposableConstructorParams The parameters for constructing a CallbackDisposable.
CombineAsyncDisposableConstructorParams The parameters for constructing a CombineAsyncDisposable.
CombineDisposableConstructorParams The parameters for constructing a CombineDisposable.
DisposableEx A Disposable that additionally exposes a convenience DisposableEx.dispose method, so a stored handle can be disposed as handle.dispose() instead of the clunkier handle[Symbol.dispose]().
Function Description
dispose Disposes a Disposable. Prefer this over calling disposable[Symbol.dispose]() at the call site: it reads better and keeps the well-known symbol referenced in a single place.
disposeAsync Disposes an AsyncDisposable. Prefer this over calling asyncDisposable[Symbol.asyncDispose]() at the call site: it reads better and keeps the well-known symbol referenced in a single place.
isAsyncDisposable Type guard to check if an object implements the AsyncDisposable interface.
isAsyncDisposableEx Type guard to check if an object implements the AsyncDisposableEx interface.
isDisposable Type guard to check if an object implements the Disposable interface.
isDisposableEx Type guard to check if an object implements the DisposableEx interface.
toAsyncDisposableEx Adapts a plain AsyncDisposable into an AsyncDisposableEx by adding a convenience AsyncDisposableEx.asyncDispose method that delegates to Symbol.asyncDispose. If the object already implements AsyncDisposableEx, it is returned unchanged.
toDisposableEx Adapts a plain Disposable into a DisposableEx by adding a convenience DisposableEx.dispose method that delegates to Symbol.dispose. If the object already implements DisposableEx, it is returned unchanged.
Type Description
AsyncDisposeCallback A callback invoked when an AsyncCallbackDisposable is disposed.
DisposeCallback A callback invoked when a CallbackDisposable is disposed.
Enum Description
DisposeErrorBehavior Determines the error semantics of a CombineDisposable or CombineAsyncDisposable when one of its children throws while being disposed.
DisposeOrder Determines the order in which a CombineDisposable or CombineAsyncDisposable disposes its children.
MultipleDisposeBehavior Determines how a CallbackDisposable or AsyncCallbackDisposable behaves when it is disposed more than once.