{"name":"on-exit-leak-free","version":"1.0.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":"^16.0.0"},"gitHead":"a4d278b0b6a58aa7722ecc59c9c6adfddcf1bc8a","_id":"on-exit-leak-free@1.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-Ve8ubhrXRdnuCJ5bQSQpP3uaV43K1PMcOfSRC1pqHgRZommXCgsXwh08jVC5NpjwScE23BPDwDvVg4cov3mwjw==","shasum":"4a2accb382278a266848bb1a21439e5fc3cd9881","tarball":"http://registry-npm.ywwl.com/on-exit-leak-free/download/on-exit-leak-free-1.0.0.tgz","fileCount":12,"unpackedSize":8254,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDqhqa4ppM06/4QbtItsxJx3Mp4Z0Q+wm9Dpy+fSgaoYwIhAMbjrk1e4n2EoTyBf5hDJEFZIZpuJi/4GlZvVPlY8NYP"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJilpSqACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmopwRAAgV+9f6ZoZM3HMUKaBQsZ5PFdXMsgptmxXMKgzNq9n1VhOcbN\r\npMdJPZ9NHY5cQLFPEpPvHu0t+07TtRnR6aQDCNWQ9Qe23qO/XP2uLb8p+hef\r\n65mMwfA501zC+5VY4/C3F/ZEDYnZTyUwshOmBrS9Tm6aKybcmwtGaI16aT5L\r\n4LqMpiTzgJuldbgExAufYCpQBwDgV7e1qFEeD4KqFkd2Y0Ap8wQ+UHsNkeRj\r\nfp7sUSEEhWEmK5VVAiMPYiuvJCVI/f6zfGlcoj4pMjlC5xMELpRQhVg+owmh\r\nhU8xbNpJdLBd9bQH0bg202B3gsAfGIusELWVkO1eHe2CR2pwvYfVKH2Te8kA\r\nhHPnLAKo0ZmXIKyYqN2WESjQRu1B4nFudN1oE3+DZL4MJWJ9fYDmNswE65MV\r\n2YF4vUqLF8gHqvxUYItT+GtrjHx8u7306GhYQpDPPCfqe8tj+xAOFKj4pxZh\r\nJAxLiO4YH93+bPlJc6/hnJzf0tgZJK4XQ9UKelGWNseshriFHsF4HkxJfs1o\r\n4t+3sofD7nUpoxqNrQ9JpT0md9iKUYvcvZ1cuFDAZ4lbSIAPLvtAVmrMhjWt\r\nJz0QcrUuLoV2LejAtHhx5VD1CUv97x6ElcFT5O1IKSwV2lKhFT+yBFkcwqsV\r\nph5FW1BOzKjqWKdb6N48V8s3Y4fRtnW0muM=\r\n=43A+\r\n-----END PGP SIGNATURE-----\r\n","size":3374,"noattachment":false,"key":"/on-exit-leak-free/-/on-exit-leak-free-1.0.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_1.0.0_1654035626574_0.6903804735611352"},"_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":1654035626685,"_cnpm_publish_time":1654035626685,"dist-tags":{"latest":"2.1.2"}}