{"name":"on-exit-leak-free","version":"2.1.2","description":"Execute a function on exit without leaking memory, allowing all objects to be garbage collected","main":"index.js","scripts":{"test":"standard | snazzy && tap test/*.js"},"repository":{"type":"git","url":"git+https://github.com/mcollina/on-exit-or-gc.git"},"keywords":["weak","reference","finalization","registry","process","exit","garbage","collector"],"author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"license":"MIT","bugs":{"url":"https://github.com/mcollina/on-exit-or-gc/issues"},"homepage":"https://github.com/mcollina/on-exit-or-gc#readme","devDependencies":{"snazzy":"^9.0.0","standard":"^17.0.0","tap":"^16.0.0"},"engines":{"node":">=14.0.0"},"_id":"on-exit-leak-free@2.1.2","gitHead":"54e85eb597d8ae9104324070ad767c120d975f2c","_nodeVersion":"18.17.1","_npmVersion":"10.1.0","dist":{"integrity":"sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==","shasum":"fed195c9ebddb7d9e4c3842f93f281ac8dadd3b8","tarball":"http://registry-npm.ywwl.com/on-exit-leak-free/download/on-exit-leak-free-2.1.2.tgz","fileCount":12,"unpackedSize":9246,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFuycuWANeHj93G7XlZJpaCdPY7TD7P/wxwytsvmz8cnAiEAhsm+OY77cQhnTj/r1F/maetBq1hsYsqnFs3nv8/6ZA8="}],"size":3658,"noattachment":false,"key":"/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/on-exit-leak-free_2.1.2_1696344125852_0.49115970753718496"},"_hasShrinkwrap":false,"readme":"# on-exit-leak-free\n\nThis module helps dispose of an object gracefully when the Node.js process exits.\nIt executes a function with a given parameter\non [`'exit'`](https://nodejs.org/api/process.html#event-exit) without leaking memory,\ncleaning things up appropriately if the object is garbage collected.\n\nRequires `WeakRef` and `FinalizationRegistry`, i.e. use Node v14+.\n\n## Install\n\n```bash\nnpm i on-exit-leak-free\n```\n\n## Example\n\n```js\n'use strict'\n\nconst { register, unregister } = require('on-exit-leak-free')\nconst assert = require('assert')\n\nfunction setup () {\n  // This object can be safely garbage collected,\n  // and the resulting shutdown function will not be called.\n  // There are no leaks.\n  const obj = { foo: 'bar' }\n  register(obj, shutdown)\n  // use registerBeforeExit(obj, shutdown) to execute the function only\n  // on beforeExit\n  // call unregister(obj) to remove\n}\n\nlet shutdownCalled = false\n\n// Please make sure that the function passed to register()\n// does not create a closure around unnecessary objects.\nfunction shutdown (obj, eventName) {\n  console.log(eventName) // beforeExit\n  shutdownCalled = true\n  assert.strictEqual(obj.foo, 'bar')\n}\n\nsetup()\n\nprocess.on('exit', function () {\n  assert.strictEqual(shutdownCalled, true)\n})\n```\n\n## License\n\nMIT\n","publish_time":1696344126031,"_cnpm_publish_time":1696344126031,"dist-tags":{"latest":"2.1.2"}}