@esfx/disposable
Version:
A low-level API for defining explicit resource management.
42 lines (29 loc) • 807 B
Markdown
The `@esfx/disposable` package provides a low-level API for defining explicit resource management that third-party libraries can use to interoperate.
* [Installation](
* [Usage](
* [API](
```sh
npm i @esfx/disposable
```
```ts
import { Disposable } from "@esfx/disposable";
class MyFileResouce {
constructor() {
this.handle = fs.openSync("path/to/file");
}
close() {
fs.closeSync(this.handle);
this.handle = undefined;
}
// provide low-level 'dispose' primitive for interop
[]() {
this.close();
}
}
```
You can read more about the API [here](https://esfx.js.org/esfx/api/disposable.html).