https://github.com/diasbruno/sbrm
Scoped bound resource management
https://github.com/diasbruno/sbrm
Last synced: about 2 months ago
JSON representation
Scoped bound resource management
- Host: GitHub
- URL: https://github.com/diasbruno/sbrm
- Owner: diasbruno
- License: unlicense
- Created: 2023-03-01T02:32:53.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-01T02:53:28.000Z (about 2 years ago)
- Last Synced: 2025-04-01T19:59:23.065Z (about 2 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# sbrm - scoped bound resource management
lisp has the `with` pattern which is also present in python.
c++ has RAII (resource acquisition is instantiation).there are 2 versions:
- scoped
```js
scope(
() => new $class(),
(instance) => instance.release()
)(
(instance) => { /* use the instance */ }
);
```- scopedClass
```js
class A {
// acquire the object
static acquire() { return new A; }
// release object
static release(i) { i.release(); }constructor() { /* acquire resources */ }
work() { return 1; }
release() { /* release stuff */ };
}scopedClass(A)(
(instance) => { /* use the instance */ }
);
```