Skip to content

Commit 5d63aed

Browse files
committed
Added module.
1 parent 32a19e5 commit 5d63aed

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

attach-exit-handler.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const attachExitHandler = async (callback) => {
2+
process.once('cleanup', async() => {
3+
await callback();
4+
});
5+
process.once('exit', async () => {
6+
process.emit('cleanup');
7+
});
8+
process.on('SIGINT', async () => {
9+
process.emit('cleanup');
10+
});
11+
process.on('SIGTERM', async () => {
12+
process.emit('cleanup');
13+
});
14+
process.on('uncaughtException', async () => {
15+
process.emit('cleanup');
16+
});
17+
};
18+
19+
export { attachExitHandler };

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@thinkdeep/attach-exit-handler",
3+
"version": "1.0.0",
4+
"description": "Attaches exit handling callback to termination signals.",
5+
"main": "attach-exit-handler.mjs",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"type": "module",
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/ThinkDeepTech/attach-exit-handler.git"
13+
},
14+
"keywords": [
15+
"Node"
16+
],
17+
"author": "Hayden McParlane",
18+
"license": "ISC",
19+
"bugs": {
20+
"url": "https://github.com/ThinkDeepTech/attach-exit-handler/issues"
21+
},
22+
"homepage": "https://github.com/ThinkDeepTech/attach-exit-handler#readme"
23+
}

0 commit comments

Comments
 (0)