npm.io
1.0.0 • Published 3 years ago

sbrm

Licence
unlicense
Version
1.0.0
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
1

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
scope(
  () => new $class(),
  (instance) => instance.release()
)(
  (instance) => { /* use the instance */ }
);
  • scopedClass
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 */ }
);

Keywords