summaryrefslogtreecommitdiff
path: root/src/utils/index.ts
diff options
context:
space:
mode:
authorKurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>2025-07-17 08:49:12 -0400
committerGitHub <noreply@github.com>2025-07-17 08:49:12 -0400
commitca0d5f0ec1f4ba21f4bf51f0f773d2b6bad45c93 (patch)
tree8374652b65877b10bce3ea6e073165a02b6af0ba /src/utils/index.ts
parent74ac6e7b7a18c2ae969b08242a5919f903d294e2 (diff)
downloadDecky-Framegen-ca0d5f0ec1f4ba21f4bf51f0f773d2b6bad45c93.tar.gz
Decky-Framegen-ca0d5f0ec1f4ba21f4bf51f0f773d2b6bad45c93.zip
reorganize for readability and DRY (#115)v0.10.1
* reorganize for readability and DRY * rm backup files * ver bump
Diffstat (limited to 'src/utils/index.ts')
-rw-r--r--src/utils/index.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/utils/index.ts b/src/utils/index.ts
new file mode 100644
index 0000000..d969cb6
--- /dev/null
+++ b/src/utils/index.ts
@@ -0,0 +1,30 @@
+import { logError } from "../api";
+
+/**
+ * Utility for creating a timer that automatically clears after specified timeout
+ * @param callback Function to call when timer completes
+ * @param timeout Timeout in milliseconds
+ * @returns Cleanup function that can be used in useEffect
+ */
+export const createAutoCleanupTimer = (callback: () => void, timeout: number): (() => void) => {
+ const timer = setTimeout(callback, timeout);
+ return () => clearTimeout(timer);
+};
+
+/**
+ * Safe wrapper for async operations to handle errors consistently
+ * @param operation Async operation to perform
+ * @param errorContext Context string for error logging
+ */
+export const safeAsyncOperation = async <T,>(
+ operation: () => Promise<T>,
+ errorContext: string
+): Promise<T | undefined> => {
+ try {
+ return await operation();
+ } catch (e) {
+ logError(`${errorContext}: ${String(e)}`);
+ console.error(e);
+ return undefined;
+ }
+};