0.0.3 • Published 7 years ago

managed-resource v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Managed-Resource

Any object allocated from this class or a class derived from it will invoke the supplied destructor right before node garbage collects the object.

The supplied handle is stored in the object (this.ref).

const Resource = require('managed-resource');

function alloc() {
}

function free(handle) {
  console.log('free!');
}

class Test extends Resource {
  constructor(handle) {
    super(() => handle, (handle) => {
      free(handle);
    });
  }
};

let x = new Test(alloc());
console.log(x.ref);
gc(); // this will print 'free!'
0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago