@andrew_l/graceful 0.0.1 → 0.2.4
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/README.md +19 -3
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Graceful Shutdown Toolkit <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
 <!-- omit in toc -->
|
|
4
|
+
 <!-- omit in toc -->
|
|
5
|
+
 <!-- omit in toc -->
|
|
6
|
+
|
|
7
|
+
This package helps gracefully shut down applications by managing dependencies during the shutdown process. It ensures that important cleanup tasks, such as closing database connections or stopping services, are completed before the application exits.
|
|
4
8
|
|
|
5
9
|
[Documentation](https://men232.github.io/toolkit/reference/@andrew_l/graceful/)
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
<!-- install placeholder -->
|
|
12
|
+
|
|
13
|
+
## 🚀 Example Usage
|
|
14
|
+
|
|
15
|
+
The following example shows how to use the package to perform a graceful shutdown for a MongoDB connection and an HTTP server:
|
|
8
16
|
|
|
9
17
|
```js
|
|
10
18
|
import { onShutdown } from '@andrew_l/graceful';
|
|
11
19
|
|
|
20
|
+
// Gracefully shutdown MongoDB connection
|
|
12
21
|
onShutdown('mongoose', ['http-server'], async () => {
|
|
13
22
|
console.info('Graceful: mongodb connection.');
|
|
14
23
|
await mongoose.disconnect();
|
|
15
24
|
});
|
|
16
25
|
|
|
26
|
+
// Gracefully shutdown HTTP server
|
|
17
27
|
onShutdown('http-server', async () => {
|
|
18
28
|
console.info('Graceful: http server.');
|
|
19
29
|
await httpServer.close();
|
|
20
30
|
});
|
|
21
31
|
```
|
|
32
|
+
|
|
33
|
+
## 🤔 Why Use This Package?
|
|
34
|
+
|
|
35
|
+
1. **Clean Shutdown:** Ensures your application cleans up resources like database connections, open files, or server instances before exiting.
|
|
36
|
+
2. **Orderly Cleanup:** Allows you to manage dependencies during shutdown, ensuring each resource is shut down in the proper order.
|
|
37
|
+
3. **Customizable:** Offers flexibility to define custom shutdown behavior for any part of your application.
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrew_l/graceful",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"graceful",
|
|
8
|
+
"shutdown"
|
|
9
|
+
],
|
|
6
10
|
"repository": {
|
|
7
11
|
"type": "git",
|
|
8
12
|
"url": "git+https://github.com/men232/toolkit.git",
|
|
@@ -20,17 +24,17 @@
|
|
|
20
24
|
"dist"
|
|
21
25
|
],
|
|
22
26
|
"devDependencies": {
|
|
23
|
-
"unbuild": "3.0.0-rc.11",
|
|
24
27
|
"@types/node": "^20.16.10",
|
|
25
28
|
"typescript": "~5.6.2",
|
|
29
|
+
"unbuild": "3.0.0-rc.11",
|
|
26
30
|
"vitest": "^2.1.3"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@andrew_l/toolkit": "0.
|
|
33
|
+
"@andrew_l/toolkit": "0.2.4"
|
|
30
34
|
},
|
|
31
35
|
"scripts": {
|
|
32
36
|
"build": "unbuild",
|
|
33
|
-
"test": "
|
|
37
|
+
"test": "echo todo",
|
|
34
38
|
"test:watch": "vitest watch --typecheck"
|
|
35
39
|
}
|
|
36
40
|
}
|