{"name":"exit-hook","version":"2.2.0","description":"Run some code when the process exits","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/exit-hook.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd"},"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","terminate","kill","stop","event","signal"],"devDependencies":{"ava":"^1.4.1","execa":"^1.0.0","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"f07fd96864d7c8c013ae8fb361ecb82d77a122f5","bugs":{"url":"https://github.com/sindresorhus/exit-hook/issues"},"homepage":"https://github.com/sindresorhus/exit-hook#readme","_id":"exit-hook@2.2.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-YFH+2oGdldRH5GqGpnaiKbBxWHMmuXHmKTMtUC58kWSOrnTf95rKITVSFTTtas14DWvWpih429+ffAvFetPwNA==","shasum":"f5502f92179018e867f2d8ee4428392da7f3894e","tarball":"http://registry-npm.ywwl.com/exit-hook/download/exit-hook-2.2.0.tgz","fileCount":5,"unpackedSize":4570,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJctg6+CRA9TVsSAnZWagAAWJwP/26izlOlBKGmPmKccKp4\nJB17pRKgczcWGDEPqF9sCCRvhlaR5PgnsXy2rQynY/i8sVTFeHpeb0J2bqaI\nSsZtR5/QJ/ZDQFkLdggJGXhtbXe1Awx/aHgIe4RlPNXShmn489gm8fv2agGp\nq0P8AUdRmM7QIrjI/yW3HuNZMhmrjnecvffb3vW09ylgLOu3hBpUdikGFisr\n7Vo7hPEry2rDYlRCKoYDIN5Eb8++VK4cORAXej66Yc5Ewbl5VWeTfjTYBmpb\nQWeHv4rXDNqqHBXBUNuBzUJ7YuYRyUIoa866AcGvcNO4oC+ULZzgte8q4tnI\nRMKPkTwiwgNsOO+qnLIeUpbt4lo1XNaQSl8Gnj0rRGB7eO93eBlp6h+z2Oet\nB2i9pcNjrcLnq9UFc9VGRhP25oN/gnvRyMOn5plOCnm7HM0EuFbCTHf6n3Me\nupyQfIpJu0bZTzjGuS9eyeHBQtW3kKGLmofhiSQEPbqUUtr30mVg8DW7u0a/\nNG2+A6GoEWM0kLZE8T1H7/IS2E4ul3AgI0nSdURAeCUwMatu3wsaZjyXUtjE\n0Ntz8f7tf1vp1b1RQV4yRclUSDN8LU64AWQG9O9ZOPC3DDaIpx+a0Mz1KlP1\nTzGc5UgcHgUIslld/lXbmjxX50V8NyEHbWTgE8PaUVjFWaLPMtfzdOtF6eVQ\nthGm\r\n=e3Mc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCS/idJTNPjwIdqLg4czCYzw0rhE5nSTaFNr0K7Az+IfQIhAJ65I1zqvy1L+q7l/Pjz7sZmPTGatgRF123G5SJtBWfB"}],"size":2187,"noattachment":false,"key":"/exit-hook/-/exit-hook-2.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/exit-hook_2.2.0_1555435197535_0.6053662791757497"},"_hasShrinkwrap":false,"readme":"# exit-hook\n\n> Run some code when the process exits\n\nThe `process.on('exit')` event doesn't catch all the ways a process can exit.\n\nThis package is useful for cleaning up before exiting.\n\n## Install\n\n```sh\nnpm install exit-hook\n```\n\n## Usage\n\n```js\nimport exitHook from 'exit-hook';\n\nexitHook(signal => {\n\tconsole.log(`Exiting with signal: ${signal}`);\n});\n\n// You can add multiple hooks, even across files\nexitHook(() => {\n\tconsole.log('Exiting 2');\n});\n\nthrow new Error('🦄');\n\n//=> 'Exiting'\n//=> 'Exiting 2'\n```\n\nRemoving an exit hook:\n\n```js\nimport exitHook from 'exit-hook';\n\nconst unsubscribe = exitHook(() => {});\n\nunsubscribe();\n```\n\n## API\n\n### exitHook(onExit)\n\nRegister a function to run during `process.exit`.\n\nReturns a function that removes the hook when called.\n\n#### onExit\n\nType: `(signal: number) => void`\n\nThe callback function to execute when the process exits.\n\n### asyncExitHook(onExit, options)\n\nRegister a function to run during `gracefulExit`.\n\nReturns a function that removes the hook when called.\n\nPlease see [Async Notes](#asynchronous-exit-notes) for considerations when using the asynchronous API.\n\n#### onExit\n\nType: `(signal: number) => (void | Promise<void>)`\n\nThe callback function to execute when the process exits via `gracefulExit`, and will be wrapped in `Promise.resolve`.\n\n#### options\n\nType: `object`\n\n##### wait\n\nType: `number`\n\nThe amount of time in milliseconds that the `onExit` function is expected to take. When multiple async handlers are registered, the longest `wait` time will be used.\n\n```js\nimport {asyncExitHook} from 'exit-hook';\n\nasyncExitHook(async () => {\n\tconsole.log('Exiting');\n}, {\n\twait: 300\n});\n\nthrow new Error('🦄');\n\n//=> 'Exiting'\n```\n\nRemoving an asynchronous exit hook:\n\n```js\nimport {asyncExitHook} from 'exit-hook';\n\nconst unsubscribe = asyncExitHook(async () => {\n\tconsole.log('Exiting');\n}, {\n\twait: 300\n});\n\nunsubscribe();\n```\n\n### gracefulExit(signal?: number): void\n\nExit the process and make a best-effort to complete all asynchronous hooks.\n\nIf you are using `asyncExitHook`, consider using `gracefulExit()` instead of `process.exit()` to ensure all asynchronous tasks are given an opportunity to run.\n\n```js\nimport {gracefulExit} from 'exit-hook';\n\ngracefulExit();\n```\n\n#### signal\n\nType: `number`\\\nDefault: `0`\n\nThe exit code to use. Same as the argument to `process.exit()`.\n\n## Asynchronous Exit Notes\n\n**tl;dr** If you have 100% control over how your process terminates, then you can swap `exitHook` and `process.exit` for `asyncExitHook` and `gracefulExit` respectively. Otherwise, keep reading to understand important tradeoffs if you're using `asyncExitHook`.\n\nNode.js does not offer an asynchronous shutdown API by default [#1](https://github.com/nodejs/node/discussions/29480#discussioncomment-99213) [#2](https://github.com/nodejs/node/discussions/29480#discussioncomment-99217), so `asyncExitHook` and `gracefulExit` will make a \"best effort\" attempt to shut down the process and run your asynchronous tasks.\n\nIf you have asynchronous hooks registered and your Node.js process is terminated in a synchronous manner, a `SYNCHRONOUS TERMINATION NOTICE` error will be logged to the console. To avoid this, ensure you're only exiting via `gracefulExit` or that an upstream process manager is sending a `SIGINT` or `SIGTERM` signal to Node.js.\n\nAsynchronous hooks should make a \"best effort\" to perform their tasks within the `wait` time, but also be written to assume they may not complete their tasks before termination.\n","publish_time":1555435197671,"_cnpm_publish_time":1555435197671,"dist-tags":{"latest":"5.1.0"}}