https://github.com/iplaylf2/resource-keeper
A tool for automatically managing and stably recycling unmanaged resources.
https://github.com/iplaylf2/resource-keeper
Last synced: 2 months ago
JSON representation
A tool for automatically managing and stably recycling unmanaged resources.
- Host: GitHub
- URL: https://github.com/iplaylf2/resource-keeper
- Owner: iplaylf2
- License: bsd-3-clause
- Created: 2023-07-30T10:59:33.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-31T09:19:19.000Z (almost 2 years ago)
- Last Synced: 2025-03-10T19:16:29.229Z (3 months ago)
- Language: TypeScript
- Size: 58.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# resource-keeper
A tool for automatically managing and stably recycling unmanaged resources.
## Usage
```typescript
import { ResourceKeeper } from "resource-keeper";(async () => {
const foo = await ResourceKeeper.create(async () => {
const foo = { count: 0 };const timer = setInterval(() => foo.count++, 100);
return [foo, async () => clearInterval(timer)];
});const unretain = foo.retain();
setInterval(() => {
if (foo.isDisposed) {
console.log("disposed");
} else {
console.log(foo.resource.count);
}
}, 100);
})();
```