@esfx/disposable Package
Provides a low-level API for defining explicit resource management that third-party libraries can use to interoperate.
Installation
npm i @esfx/disposable
Usage
import { Disposable } from "@esfx/disposable";
import * as fs from "fs";
class MyFileResouce {
private _handle?: number;
constructor() {
this._handle = fs.openSync("path/to/file", "r");
}
close() {
if (this._handle !== undefined) {
fs.closeSync(this._handle);
this._handle = undefined;
}
}
// provide low-level 'dispose' primitive for interop
[Disposable.dispose]() {
this.close();
}
}
Classes
AsyncDisposable
Indicates an object that has resources that can be explicitly disposed asynchronously.
NOTE: It is not necessary to subclass AsyncDisposable
. Merely having an [AsyncDisposable.asyncDispose]()
method is sufficient.
AsyncDisposableStack
A container for asynchronously disposable resources. When the stack is disposed, its containing resources are disposed in the reverse of the order in which they were added.
Disposable
Indicates an object that has resources that can be explicitly disposed.
DisposableStack
A container for disposable resources. When the stack is disposed, its containing resources are disposed in the reverse of the order in which they were added.
Interfaces
AsyncDisposable
Indicates an object that has resources that can be explicitly disposed asynchronously.
AsyncDisposableScope
Disposable
Indicates an object that has resources that can be explicitly disposed.
DisposableScope
Used to aproximate using const
via for..of
. See scope().
NOTE: This is not spec-compliant and will not be standardized.
Type Aliases
AsyncDisposableLike
Warning
Deprecated
Use instead.Declaration
export declare type AsyncDisposableLike = AsyncDisposable | Disposable | (() => void | PromiseLike<void>);
DisposableLike
Warning
Deprecated
UseDeclaration
export declare type DisposableLike = Disposable | (() => void);
Namespaces
AsyncDisposable
Disposable
Indicates an object that has resources that can be explicitly disposed.