import { LeaderServiceOptions } from './leader';
export type MeshMessageMap = Record<string, {
    request: unknown;
    response: unknown;
}>;
export type MeshBroadcastMap = Record<string, unknown>;
export interface MeshBroadcastOptions {
    skipSelf?: boolean;
}
export interface MeshNode {
    instanceId: number;
    hostname: string;
    self: boolean;
}
export interface MeshServiceOptions {
    heartbeatIntervalMs?: number;
    nodeTtlMs?: number;
    requestTimeoutMs?: number;
    leaderOptions?: LeaderServiceOptions;
}
export declare class MeshRequestTimeoutError extends Error {
    constructor(instanceId: number, type: string);
}
export declare class MeshHandlerError extends Error {
    constructor(message: string);
}
export declare class MeshNoHandlerError extends Error {
    constructor(type: string);
}
export declare function destroyMeshRedis(): void;
export declare class MeshService<T extends MeshMessageMap, B extends MeshBroadcastMap = {}> {
    private _instanceId;
    private key;
    private prefix;
    private running;
    private heartbeatIntervalMs;
    private nodeTtlMs;
    private requestTimeoutMs;
    private leaderOptions?;
    private heartbeatTimer;
    private leaderService;
    private subscriberClient;
    private handlers;
    private broadcastHandlers;
    private pendingRequests;
    private activeHandlerIntervals;
    private nodeCleanedUpCallback;
    private logger;
    constructor(key: string, options?: MeshServiceOptions);
    get instanceId(): number;
    registerHandler<K extends keyof T & string>(type: K, handler: (data: T[K]['request']) => T[K]['response'] | Promise<T[K]['response']>): void;
    registerBroadcastHandler<K extends keyof B & string>(type: K, handler: (data: B[K], senderInstanceId: number) => void | Promise<void>): void;
    setNodeCleanedUpCallback(cb: (instanceId: number) => void | Promise<void>): void;
    getNodes(): Promise<MeshNode[]>;
    invoke<K extends keyof T & string>(instanceId: number, type: K, data: T[K]['request'], timeoutMs?: number): Promise<T[K]['response']>;
    broadcast<K extends keyof B & string>(type: K, data: B[K], options?: MeshBroadcastOptions): Promise<void>;
    start(): Promise<void>;
    stop(): Promise<void>;
    private nextIdKey;
    private heartbeatsKey;
    private nodesKey;
    private channelForInstance;
    private broadcastChannel;
    private doHeartbeat;
    private doCleanup;
    private handleBroadcastIncoming;
    private handleBroadcastMessage;
    private handleMessage;
    private handleHeartbeatMessage;
    private handleResponseMessage;
    private handleRequestMessage;
}
export declare type __ΩMeshMessageMap = any[];
export declare type __ΩMeshBroadcastMap = any[];
export declare type __ΩMeshBroadcastOptions = any[];
export declare type __ΩMeshNode = any[];
export declare type __ΩMeshServiceOptions = any[];
//# sourceMappingURL=mesh.d.ts.map