@guava-ai/guava-sdk 0.29.0 → 0.30.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/src/utils.ts CHANGED
@@ -63,3 +63,41 @@ export async function fetchOrThrow(
63
63
 
64
64
  return res;
65
65
  }
66
+
67
+ /** A Disposable whose disposal does nothing. Useful as a conditional no-op. */
68
+ export const nullDisposable: Disposable = { [Symbol.dispose]() {} };
69
+
70
+ export function onAbort(signal: AbortSignal, listener: () => void): Disposable {
71
+ signal.throwIfAborted();
72
+ signal.addEventListener("abort", listener, { once: true });
73
+
74
+ return {
75
+ [Symbol.dispose]() {
76
+ signal.removeEventListener("abort", listener);
77
+ },
78
+ };
79
+ }
80
+
81
+ export function onSignal(handler: (signal: "SIGINT" | "SIGTERM") => void): Disposable {
82
+ // Remove both handlers on the first signal so any second signal (of either
83
+ // type) falls through to Node's default behavior and terminates the process.
84
+ const remove = () => {
85
+ process.off("SIGINT", sigint);
86
+ process.off("SIGTERM", sigterm);
87
+ };
88
+ const sigint = () => {
89
+ remove();
90
+ handler("SIGINT");
91
+ };
92
+ const sigterm = () => {
93
+ remove();
94
+ handler("SIGTERM");
95
+ };
96
+
97
+ process.on("SIGINT", sigint);
98
+ process.on("SIGTERM", sigterm);
99
+
100
+ return {
101
+ [Symbol.dispose]: remove,
102
+ };
103
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.29.0";
1
+ export const SDK_VERSION = "0.30.0";