syncguard
Version:
Functional TypeScript library for distributed locking across microservices. Prevents race conditions with Redis, Firestore, and custom backends. Features automatic lock management, timeout handling, and extensible architecture.
26 lines (25 loc) • 878 B
TypeScript
import type { FirestoreConfig } from "./types.js";
/**
* Checks if an error is transient and should be retried
*/
export declare function isTransientError(error: unknown): boolean;
/**
* Handles retry logic for Firestore operations
* Throws on failure after exhausting retries for transient errors
*/
export declare function withRetries<T>(operation: () => Promise<T>, config: FirestoreConfig): Promise<T>;
/**
* Specialized retry logic for lock acquisition operations
* Handles both lock contention (always retry) and system errors (transient retry only)
*/
export declare function withAcquireRetries(operation: () => Promise<{
acquired: boolean;
lockId?: string;
expiresAt?: number;
reason?: string;
}>, config: FirestoreConfig, timeoutMs: number): Promise<{
acquired: boolean;
lockId?: string;
expiresAt?: number;
reason?: string;
}>;