{"name":"on-exit-leak-free","version":"0.2.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":"54a91f80aad1f026b9ef82114ef8bf0c3c45b600","_id":"on-exit-leak-free@0.2.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"dist":{"integrity":"sha512-dqaz3u44QbRXQooZLTUKU41ZrzYrcvLISVgbrzbyCMxpmSLJvZ3ZamIJIZ29P6OhZIkNIQKosdeM6t1LYbA9hg==","shasum":"b39c9e3bf7690d890f4861558b0d7b90a442d209","tarball":"http://registry-npm.ywwl.com/on-exit-leak-free/download/on-exit-leak-free-0.2.0.tgz","fileCount":11,"unpackedSize":7664,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg+rcZCRA9TVsSAnZWagAA1OEP/jyLIS1dbYAgQHKz1Htn\nbJ8lRhaSPW4D7xC+G20PfESdp5gjT4+lLYN2S7/byk8OMQCqsV++OhTmKZIm\nOjtjA7+s9NTHP0BNnPgrLSKY2S2+yj05QGYl6rc99tHMiFOVx0CspHRLGao0\nnBRL9pjUQLA8ZYvIozCFqkSG+kgKarXejfld5WUWiGIbYOtd20IoYQApU9Kt\n6SOe2JDJbK3ZSUV8IG/oeTuI/fr1ErJWZ8L2e+CIFhMUiBbGMv6LEsCEGufe\n6034yZXFThMkrISpeNL70wn1OIJK1+WPXc+egHSj1uh0HG/zSc7c1E0+iWnG\n+ts/8nqBcUzUV7QCNvc1ENr3JYdv5j8trs37oM0ax9xvLJiB/jLYF/z5Rksd\nV19JmACO8zO3m1w6GB4F56t6c2HZFFaySg4yfXiz56lmC7MLcxbya+lyyiA9\nrZktWoDmSj7EDq0SDLV9TO+EwzUceXGYfEWpi4b4HRKIC0IwOaPJ58yf78Bf\nWlX0Z55RKKh14rUhPxV9L5lOgCpt5DhQ8BK0mKQeesZHfl22+rB86nfUUcqu\nnt6mhJbXrfB/Od59Mj7oyeFhpCfLufTAANNiPqyAIU48WKz6QpJzRI6FBDj+\nz6tXZnVgezmfJ2paV9/yiJHhOAuZ0CG1mh2kUzMWLBogGCOg5EmAcZD6gZ7o\nsMSD\r\n=aB4R\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEnwvhwkPzymv/HOEU4h8y9jj50HmAPC55IQmADFE7uOAiAY23gxEeOc9tz0Fx4SKTs2uMr5Jtu+fNSmy7qyxgc/4w=="}],"size":3212,"noattachment":false,"key":"/on-exit-leak-free/-/on-exit-leak-free-0.2.0.tgz"},"directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/on-exit-leak-free_0.2.0_1627043608881_0.5131187509186566"},"_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":1627043609009,"_cnpm_publish_time":1627043609009,"dist-tags":{"latest":"2.1.2"}}