{"name":"on-exit-leak-free","version":"2.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":"^17.0.0","tap":"^16.0.0"},"gitHead":"6c083e84d7007e252380098e574dceccabdf36ca","_id":"on-exit-leak-free@2.0.0","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-/yD7zxeQIpvrU4DHfh2d9ujf8RauHQgIaWS8kHQPgWVDZo43Ho0WdNow1JuXCsBSTlxIMCSo/WyLkLEaKFItrQ==","shasum":"c3bfe669f2c7c3a372eea38a71ec301484dabe1c","tarball":"http://registry-npm.ywwl.com/on-exit-leak-free/download/on-exit-leak-free-2.0.0.tgz","fileCount":11,"unpackedSize":7500,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmHew4sdfUFA3c+eQ8qoqOkPTwFXJ8/ze+cIEd1t3h9gIhAKC+Eg8VFDRYG0JM7k0Oyrv5reLfK4DChfvhbszRGwWe"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJissr6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpvBBAAoBE4gWm3WtSonYrnSsEqlSIIf6ve2bwqh5qYP/NYVGgxJcVe\r\nWHqV6p9X3HNeahytzZxOHdAhX8nFpO3Sr2P6Azpq5+UPrJGirLIENHiZV5Cb\r\nlZJM71JkOKGoSQZDHQnHC2GicLcY9t7NljT8DUnm/Av4kXW7gPGGb4M4L97F\r\nDtlQx7Rpko6KfMwlRRGqanr0hpJDv1I/qSWPakfba1HjC+P41iyMpRLs4pm5\r\nbjP/67qqIOh/d/HTkQKg5fTfAkLj90PzRAXS+G7gaO0sFM37/ktT8esmfC+K\r\n6I8638T454sBwy+YgtWMfOYNj5CYSLcpyhyamD3MXpD7gdeEYdyt6EpZefdr\r\nJhWFts3unoHSk/5chkfh76IzbM1bvBmLMCuVY/+DRhKmNCPEWMMiz4DGpZQl\r\nXCHAQM5Zj6pcwIwIZznCmh4aJEuQySHfFKKDsdeGwyUiVJfUPwUsh2pHSC+T\r\ncLsmcy4TkMsSqr7L1b1fpBjA4SkELhJk2ZhW0LSYplmRaMMpTSsb26lsknxK\r\nf9en0rZPafWE9qisVKhYrDAY1B8XrUxAeDBb7bKFnnI3a3Vx0dFrP8JWx6Ln\r\n9QwddlcvvIjJC6yJYqb+CKGEA2WWzB9/pVc2f7J6m0cgeRZ8fYW9JqoEUy6M\r\n3FyUI/4OlKf/B4fFJOE27SZcGKoknlP2Cfo=\r\n=Hh2S\r\n-----END PGP SIGNATURE-----\r\n","size":3282,"noattachment":false,"key":"/on-exit-leak-free/-/on-exit-leak-free-2.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_2.0.0_1655884537952_0.5797627759684092"},"_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":1655884538120,"_cnpm_publish_time":1655884538120,"dist-tags":{"latest":"2.1.2"}}