{"name":"on-exit-leak-free","version":"0.1.0","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":"^16.0.3","tap":"^15.0.9"},"gitHead":"082429dd2cc5d5ca757a755d92813c2d00179f38","_id":"on-exit-leak-free@0.1.0","_nodeVersion":"14.17.2","_npmVersion":"6.14.13","dist":{"integrity":"sha512-BsvTPagoHPkkV0XqKScPP/v5wquP3DYlyhCDMG7KQHXByU3ViuCZjJqESlV7PFynY/i4uiqQoKIZUOlxjtjO3A==","shasum":"499c139a097e46d82ae40f1802462a3d1adf6251","tarball":"http://registry-npm.ywwl.com/on-exit-leak-free/download/on-exit-leak-free-0.1.0.tgz","fileCount":10,"unpackedSize":6576,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg5VZSCRA9TVsSAnZWagAACigP/RbQXnmEMLudaNALmjfu\n87dZrFh8cPfKYwvHhz6tt6IHMtYh1f6iy6XgSQuPG7sR81fDLCkSQ3EraJCE\nJJVzUxcrh2Y2veU/xhIoEUR24BuXxiQlj4yJv5cVMknxWmMwOxTp3aeWiYpA\nlfFT/a8Gd/ILN/+Be0ccycp9H+ST5T2z3jkjYYaNxaBNZzbEN8qT13Ee6SRo\nuREd/9iLHkWMfp/DjurvmZk7Too8nxHYl6pqvoks5PXrrT6STAfVRDpRBOM4\nGjBvgbEmk6538oNPTlEywhLA95+LMKTgOX/CkBM+m15axYH+gTeLjVEh3cWM\ntlxDDHR1q/jZKlczNIe7zg6qJAIOcuyU1qSlYHuAJR5RSZ8fwt4wP1W7ZM1d\nmMl+wQM9JS9tKeoLW5j2dAYjZag9SeDVjz9qVNwtX+9XF+goMbPhvBjpXIpg\n8EdhHd/aQwLXzgyE9uWvgw4/f8rA6gw6Yi5gvJzg49gPgfEOaSet1uJp7xbh\nlCHJnyNFvm8skZaa9XDIVaamhnT39n4X68AGJRpwCbYg3waUvdE2j8MGyl0A\nCRSQslDzpwUHzso5UohKb1iFv/7780CAktOcP+RMGQ9EFzKD8RvCP9zb7xJk\nclKGl9p4MTsz6HQb7MtG8wuQPIkQDAAto/MThtSQqWuwFihKk8D6YJJ3f4bM\nhX5m\r\n=QwOF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCSVyzJsnTMCRc7hWkC00VnnOyHzfG4pvflql8KarJt7wIhAPSSYg/e24/sDYmwjU4q2G5f6HoVf5MJSRGJFpQz2l+g"}],"size":2919,"noattachment":false,"key":"/on-exit-leak-free/-/on-exit-leak-free-0.1.0.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_0.1.0_1625642577785_0.1927204270556615"},"_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":1625642577929,"_cnpm_publish_time":1625642577929,"dist-tags":{"latest":"2.1.2"}}