@breadc/death 0.9.7-beta.0 → 0.9.7

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/index.cjs CHANGED
@@ -34,6 +34,14 @@ function onDeath(callback, { SIGINT = true, SIGTERM = true, SIGQUIT = true } = {
34
34
  }
35
35
  };
36
36
  }
37
+ function useDeath(callback, options = {}) {
38
+ const cancel = onDeath(callback, options);
39
+ return {
40
+ [Symbol.dispose]: () => {
41
+ cancel();
42
+ }
43
+ };
44
+ }
37
45
  function registerCallback(signal, handler) {
38
46
  if (handler.count === 0) {
39
47
  handler.count += 1;
@@ -92,3 +100,4 @@ function makeHandler(signal) {
92
100
  }
93
101
 
94
102
  exports.onDeath = onDeath;
103
+ exports.useDeath = useDeath;
@@ -0,0 +1,19 @@
1
+ type DeathSignals = 'SIGINT' | 'SIGTERM' | 'SIGQUIT';
2
+ interface OnDeathContext {
3
+ triggered: boolean;
4
+ terminate: 'exit' | 'kill' | false;
5
+ exit: number | undefined;
6
+ kill: NodeJS.Signals | undefined;
7
+ }
8
+ type OnDeathCallback = (signal: DeathSignals, context: OnDeathContext) => unknown | Promise<unknown>;
9
+ interface OnDeathOptions {
10
+ SIGINT?: boolean;
11
+ SIGTERM?: boolean;
12
+ SIGQUIT?: boolean;
13
+ }
14
+ declare function onDeath(callback: OnDeathCallback, { SIGINT, SIGTERM, SIGQUIT }?: OnDeathOptions): () => void;
15
+ declare function useDeath(callback: OnDeathCallback, options?: OnDeathOptions): {
16
+ [Symbol.dispose]: () => void;
17
+ };
18
+
19
+ export { type DeathSignals, type OnDeathCallback, type OnDeathContext, type OnDeathOptions, onDeath, useDeath };
@@ -0,0 +1,19 @@
1
+ type DeathSignals = 'SIGINT' | 'SIGTERM' | 'SIGQUIT';
2
+ interface OnDeathContext {
3
+ triggered: boolean;
4
+ terminate: 'exit' | 'kill' | false;
5
+ exit: number | undefined;
6
+ kill: NodeJS.Signals | undefined;
7
+ }
8
+ type OnDeathCallback = (signal: DeathSignals, context: OnDeathContext) => unknown | Promise<unknown>;
9
+ interface OnDeathOptions {
10
+ SIGINT?: boolean;
11
+ SIGTERM?: boolean;
12
+ SIGQUIT?: boolean;
13
+ }
14
+ declare function onDeath(callback: OnDeathCallback, { SIGINT, SIGTERM, SIGQUIT }?: OnDeathOptions): () => void;
15
+ declare function useDeath(callback: OnDeathCallback, options?: OnDeathOptions): {
16
+ [Symbol.dispose]: () => void;
17
+ };
18
+
19
+ export { type DeathSignals, type OnDeathCallback, type OnDeathContext, type OnDeathOptions, onDeath, useDeath };
package/dist/index.d.ts CHANGED
@@ -12,5 +12,8 @@ interface OnDeathOptions {
12
12
  SIGQUIT?: boolean;
13
13
  }
14
14
  declare function onDeath(callback: OnDeathCallback, { SIGINT, SIGTERM, SIGQUIT }?: OnDeathOptions): () => void;
15
+ declare function useDeath(callback: OnDeathCallback, options?: OnDeathOptions): {
16
+ [Symbol.dispose]: () => void;
17
+ };
15
18
 
16
- export { DeathSignals, OnDeathCallback, OnDeathContext, OnDeathOptions, onDeath };
19
+ export { type DeathSignals, type OnDeathCallback, type OnDeathContext, type OnDeathOptions, onDeath, useDeath };
package/dist/index.mjs CHANGED
@@ -32,6 +32,14 @@ function onDeath(callback, { SIGINT = true, SIGTERM = true, SIGQUIT = true } = {
32
32
  }
33
33
  };
34
34
  }
35
+ function useDeath(callback, options = {}) {
36
+ const cancel = onDeath(callback, options);
37
+ return {
38
+ [Symbol.dispose]: () => {
39
+ cancel();
40
+ }
41
+ };
42
+ }
35
43
  function registerCallback(signal, handler) {
36
44
  if (handler.count === 0) {
37
45
  handler.count += 1;
@@ -89,4 +97,4 @@ function makeHandler(signal) {
89
97
  };
90
98
  }
91
99
 
92
- export { onDeath };
100
+ export { onDeath, useDeath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breadc/death",
3
- "version": "0.9.7-beta.0",
3
+ "version": "0.9.7",
4
4
  "description": "Easily register termination signals callbacks.",
5
5
  "keywords": [
6
6
  "breadc",
@@ -37,8 +37,8 @@
37
37
  "dist"
38
38
  ],
39
39
  "devDependencies": {
40
- "@types/node": "^18.17.5",
41
- "vitest": "^0.33.0"
40
+ "@types/node": "^20.8.7",
41
+ "vitest": "^0.34.6"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild",