import { type RedisConnection } from './redis';
export type MutexKey = any;
export interface MutexContext {
    key: string;
    lockId?: string;
    signal: AbortSignal;
    assertNotAborted(): void;
}
export type MutexFn<R = unknown> = (didWait: boolean, context?: MutexContext) => Promise<R>;
export interface MutexOptions<T> {
    key: MutexKey | MutexKey[];
    fn: MutexFn<T>;
    retryCount?: number;
    retryDelay?: number;
    renewInterval?: number;
    mode?: 'local' | 'redis';
    redis?: RedisMutexProvider;
    signal?: AbortSignal;
}
export interface RedisMutexClient {
    eval(script: string, numberOfKeys: 1, key: string, ...args: Array<string | number>): Promise<unknown> | unknown;
}
export type RedisMutexProvider = () => RedisConnection<RedisMutexClient>;
export interface MutexObservation {
    id: string;
    key: string;
    mode: 'local' | 'redis';
    type: 'pending' | 'acquired' | 'released' | 'error' | 'failed';
    startedAt: number;
    at: number;
    waited?: boolean;
    error?: unknown;
}
export type MutexObserver = (entry: MutexObservation) => void;
export declare class MutexAcquisitionError extends Error {
    constructor(message?: string);
}
export declare function withMutex<T>(options: MutexOptions<T>): Promise<T>;
export declare function registerMutexObserver(observer: MutexObserver): () => void;
export declare function withMutexes<T>(options: Omit<MutexOptions<T>, 'key'> & {
    keys: Array<MutexOptions<T>['key']>;
}): Promise<T>;
export declare function flattenMutexKey(key: MutexKey | MutexKey[]): string;
export declare function resetMutexRedisConnection(): void;
//# sourceMappingURL=mutex.d.ts.map