Exports the native bindings used internally by the weak-napi
package.
const { ObjectInfo } = require("@mhofman/weak-napi-native");
// or
const ObjectInfo = require("@mhofman/weak-napi-native/object-info");
let obj = {};
// The callback is currently mandatory even if not using
let info = new ObjectInfo(obj, () => {});
console.log(info.target === obj);
obj = undefined;
setImmediate(() => {
gc();
console.log(info.target === undefined);
});
const { ObjectInfo, WeakTag } = require("@mhofman/weak-napi-native");
// or
const ObjectInfo = require("@mhofman/weak-napi-native/object-info");
const WeakTag = require("@mhofman/weak-napi-native/weak-tag");
const weakMap = new WeakMap();
let obj = {};
let info = new ObjectInfo(obj, () => {
console.log("obj was collected");
});
// There should only be one `WeakTag` per `ObjectInfo`
weakMap.set(obj, new WeakTag(info));
obj = undefined;
setImmediate(gc);