@alwatr/exit-hook 9.2.1 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/package.json +4 -4
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 📦 @alwatr/exit-hook v9.
|
|
1
|
+
/* 📦 @alwatr/exit-hook v9.4.0 */
|
|
2
2
|
var q=null,y=!1;function D(f){if(q===null)B(),q=[];q.push(f)}function u(f){if(console.log("onExit({signal: %s})",f),y===!0||q===null)return;y=!0;for(let z of q)try{z()}catch(A){console.error("Error in exit hook callback:",A)}if(f==="SIGINT"||f==="SIGTERM")setTimeout(()=>{process.exit(0)})}function B(){process.once("exit",u),process.once("SIGTERM",u),process.once("SIGINT",u)}export{D as exitHook};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=D07DA18E4F8DD98E64756E2164756E21
|
|
5
5
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"/**\n * Array of callback functions to be called when the process is exiting.\n */\nlet callbacks: (() => void)[] | null = null;\n\n/**\n * True whether the process is exiting to prevent calling the callbacks more than once.\n */\nlet exiting = false;\n\n/**\n * Add a callback function to be called when the process is exiting.\n *\n * @param callback The callback function to be called when the process is exiting.\n *\n * @example\n * ```typescript\n * const saveAllData = () => {\n * // save all data\n * };\n *\n * existHook(saveAllData);\n * ```\n */\nexport function exitHook(callback: () => void): void {\n if (callbacks === null) {\n registerExitEvents();\n callbacks = [];\n }\n callbacks.push(callback);\n}\n\n/**\n * A once callback to be called on process exit event.\n */\nfunction onExit_(signal: number | 'SIGINT' | 'SIGTERM') {\n console.log('onExit({signal: %s})', signal);\n if (exiting === true || callbacks === null) return;\n\n exiting = true;\n\n for (const callback of callbacks) {\n try {\n callback();\n }\n catch (error) {\n console.error('Error in exit hook callback:', error);\n }\n }\n\n if (signal === 'SIGINT' || signal === 'SIGTERM') {\n setTimeout(() => {\n process.exit(0);\n });\n }\n}\n\n/**\n * Register process exit events.\n */\nfunction registerExitEvents(): void {\n /**\n * This event emitted when Node.js empties its event loop and has no additional work to schedule.\n * Normally, the Node.js process will exit when there is no work scheduled,\n * but a listener registered on the 'beforeExit' event can make **asynchronous calls**, and thereby cause the Node.js process to continue.\n *\n * @see https://nodejs.org/api/process.html#event-beforeexit\n */\n // process.once('beforeExit', onExit_);\n\n /**\n * This event is emitted when the Node.js process is about to exit as a result of either:\n * 1- The `process.exit()` method being called explicitly.\n * 2- The Node.js event loop no longer having any additional work to perform.\n *\n * @see https://nodejs.org/api/process.html#event-exit\n */\n process.once('exit', onExit_);\n\n /**\n * This event is emitted in terminal mode before exiting with code 128 + signal number.\n *\n * @see https://nodejs.org/api/process.html#signal-events\n */\n process.once('SIGTERM', onExit_);\n\n /**\n * This event is emitted when `Ctrl+C` is pressed.\n *\n * @see https://nodejs.org/api/process.html#signal-events\n */\n process.once('SIGINT', onExit_);\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAGA,IAAI,EAAmC,KAKnC,EAAU,GAgBP,SAAS,CAAQ,CAAC,EAA4B,CACnD,GAAI,IAAc,KAChB,EAAmB,EACnB,EAAY,CAAC,EAEf,EAAU,KAAK,CAAQ,EAMzB,SAAS,CAAO,CAAC,EAAuC,CAEtD,GADA,QAAQ,IAAI,uBAAwB,CAAM,EACtC,IAAY,IAAQ,IAAc,KAAM,OAE5C,EAAU,GAEV,QAAW,KAAY,EACrB,GAAI,CACF,EAAS,EAEX,MAAO,EAAO,CACZ,QAAQ,MAAM,+BAAgC,CAAK,EAIvD,GAAI,IAAW,UAAY,IAAW,UACpC,WAAW,IAAM,CACf,QAAQ,KAAK,CAAC,EACf,EAOL,SAAS,CAAkB,EAAS,CAiBlC,QAAQ,KAAK,OAAQ,CAAO,EAO5B,QAAQ,KAAK,UAAW,CAAO,EAO/B,QAAQ,KAAK,SAAU,CAAO",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "D07DA18E4F8DD98E64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/exit-hook",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "A utility for registering exit handlers in Node.js.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@alwatr/nano-build": "9.
|
|
25
|
-
"@alwatr/
|
|
24
|
+
"@alwatr/nano-build": "9.3.0",
|
|
25
|
+
"@alwatr/standard": "9.4.0",
|
|
26
26
|
"@alwatr/type-helper": "9.1.1",
|
|
27
27
|
"@types/node": "^24.12.2",
|
|
28
28
|
"typescript": "^6.0.2"
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"utility",
|
|
72
72
|
"utils"
|
|
73
73
|
],
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "662f1047fc2a1b53a00902028d6cebfd04b52dd5"
|
|
75
75
|
}
|