{"name":"on-exit-leak-free","version":"2.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":"^17.0.0","tap":"^16.0.0"},"gitHead":"223fd00d674f841b8785eeb3d7b0f8e2f2b9e003","_id":"on-exit-leak-free@2.1.0","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w==","shasum":"5c703c968f7e7f851885f6459bf8a8a57edc9cc4","tarball":"http://registry-npm.ywwl.com/on-exit-leak-free/download/on-exit-leak-free-2.1.0.tgz","fileCount":12,"unpackedSize":8885,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDZD9+7egZIExdBtJRDtkbif+MwJdQiRRi/eLnuborumwIhAJiscqXiJdzy4k19GqNyJJwItLJSx8CCVxGHwXr6PJwo"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJisuCcACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoMrA/6A1r8aqUhUA9wlAT2Ew69FDyNkCr6U0C6WPxN6WmYmq9bADLJ\r\nhpEfXS94OWr8wqxjDbHHWfEJwUCdDSxhmwIohU4T4nfOSCjhC1QPysWP+vAr\r\nGH1AneLYZrrvkf4chjOALYTH13KRmZBLEF8YJ7wuF2PJdIgYrOCSbPgNFICa\r\n4ihWXUn/BsSIuQa9loJMKAD/ky5lp07jUC6C5IgXNZkw9KQWDrAYOleK0DJC\r\nUmrISSMhLn3mw/dfWlFKN8bU2ICT5TPPNjwR5A06QlXCBiYfVNWwkCwofvEW\r\nQHNVu0wtMeofsllgRyC1L2l+BkMo7ZcPYJPE+KRDciYB8LwnQiRJK+Glkh0e\r\nYThAwGUsqs+jf0GksEhsbDkBcgE/JopoRA1fsZzixklD4BAGAMNeITmpREFE\r\nGbO6JzSnCQn+FzWGUizKeusgAeqp9b2AcZ/QUwxBl5oDgqT2dlhR9dzgEutV\r\nax9ya422E8BSSYCmJfTAxEU5M073hnEwSMXZOj4V2uBmkl98dFMGffHWVqeK\r\nAzo7TokhcsegvaDaAku0ppwIVSQ5I1+YEWJ+gs8RsbbPqorMY0SM5dVnhekP\r\nxkXPzXJdBRuVkPzcnR7F2+UjZngv9QenR4Fb1Rml97dw1BxRaIq+kSyDO6Po\r\nGvMe1Qm+FdIK0HIkZ/TkcjKKxOk/xsv2W+k=\r\n=xN9Z\r\n-----END PGP SIGNATURE-----\r\n","size":3560,"noattachment":false,"key":"/on-exit-leak-free/-/on-exit-leak-free-2.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_2.1.0_1655890075938_0.8722406181041178"},"_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":1655890076120,"_cnpm_publish_time":1655890076120,"dist-tags":{"latest":"2.1.2"}}