feat(store): queue task refactor (#287)

This commit is contained in:
rahim
2026-01-05 16:24:18 +11:00
committed by GitHub
parent 44cd824f3b
commit 6a7acdabfe
9 changed files with 941 additions and 296 deletions
+28
View File
@@ -0,0 +1,28 @@
/**
* Wrap a function to catch and handle errors instead of throwing.
*
* @param fn - Function to wrap (can be undefined)
* @param onError - Error handler (defaults to console.error)
* @returns Wrapped function that never throws, or undefined if fn is undefined
*
* @example
* ```ts
* const safeFn = tryCatch(riskyFn, (e) => logger.error(e));
* safeFn?.(); // Never throws
* ```
*/
export function tryCatch<T extends (...args: any[]) => unknown>(
fn: T | undefined,
onError: (error: unknown) => void = console.error,
): T | undefined {
if (!fn) return undefined;
return ((...args: Parameters<T>) => {
try {
return fn(...args);
} catch (error) {
onError(error);
return undefined;
}
}) as T;
}