@mhofman/weak-napi-native
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@mhofman/weak-napi-native

Native bindings of the weak-napi package

Exports the native bindings used internally by the weak-napi package.

ObjectInfo

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);
});

WeakTag

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);

Package Sidebar

Install

npm i @mhofman/weak-napi-native

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

2.48 kB

Total Files

8

Last publish

Collaborators

  • mhofman