pax_global_header00006660000000000000000000000064124010706560014513gustar00rootroot0000000000000052 comment=10367d283104d4b5d520d7f5c77f772d642b0f02 exit-hook-1.1.1/000077500000000000000000000000001240107065600134225ustar00rootroot00000000000000exit-hook-1.1.1/.editorconfig000066400000000000000000000003371240107065600161020ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [package.json] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false exit-hook-1.1.1/.gitattributes000066400000000000000000000000141240107065600163100ustar00rootroot00000000000000* text=auto exit-hook-1.1.1/.gitignore000066400000000000000000000000151240107065600154060ustar00rootroot00000000000000node_modules exit-hook-1.1.1/.jshintrc000066400000000000000000000002761240107065600152540ustar00rootroot00000000000000{ "node": true, "esnext": true, "bitwise": true, "camelcase": true, "curly": true, "immed": true, "newcap": true, "noarg": true, "undef": true, "unused": "vars", "strict": true } exit-hook-1.1.1/.travis.yml000066400000000000000000000000461240107065600155330ustar00rootroot00000000000000language: node_js node_js: - '0.10' exit-hook-1.1.1/index.js000066400000000000000000000006741240107065600150760ustar00rootroot00000000000000'use strict'; var cbs = []; var called = false; function exit(exit, signal) { if (called) { return; } called = true; cbs.forEach(function (el) { el(); }); if (exit === true) { process.exit(128 + signal); } }; module.exports = function (cb) { cbs.push(cb); if (cbs.length === 1) { process.once('exit', exit); process.once('SIGINT', exit.bind(null, true, 2)); process.once('SIGTERM', exit.bind(null, true, 15)); } }; exit-hook-1.1.1/license000066400000000000000000000021371240107065600147720ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. exit-hook-1.1.1/package.json000066400000000000000000000012261240107065600157110ustar00rootroot00000000000000{ "name": "exit-hook", "version": "1.1.1", "description": "Run some code when the process exits", "license": "MIT", "repository": "sindresorhus/exit-hook", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "http://sindresorhus.com" }, "engines": { "node": ">=0.10.0" }, "scripts": { "test": "node test.js" }, "files": [ "index.js" ], "keywords": [ "exit", "quit", "process", "hook", "graceful", "handler", "shutdown", "sigterm", "sigint", "terminate", "kill", "stop", "event" ], "devDependencies": { "ava": "0.0.4" } } exit-hook-1.1.1/readme.md000066400000000000000000000012441240107065600152020ustar00rootroot00000000000000# exit-hook [![Build Status](https://travis-ci.org/sindresorhus/exit-hook.svg?branch=master)](https://travis-ci.org/sindresorhus/exit-hook) > Run some code when the process exits The `process.on('exit')` event doesn't catch all the ways a process can exit. Useful for cleaning up. ## Install ```sh $ npm install --save exit-hook ``` ## Usage ```js var exitHook = require('exit-hook'); exitHook(function () { console.log('exiting'); }); // you can add multiple hooks, even across files exitHook(function () { console.log('exiting 2'); }); throw new Error('unicorns'); //=> exiting //=> exiting 2 ``` ## License MIT © [Sindre Sorhus](http://sindresorhus.com) exit-hook-1.1.1/test.js000066400000000000000000000003361240107065600147410ustar00rootroot00000000000000'use strict'; var test = require('ava'); var exitHook = require('./'); test(function (t) { t.plan(2); exitHook(function () { t.assert(true); }); exitHook(function () { t.assert(true); }); process.exit(); });