/// <reference types="node" />
import EventEmitter from './ee';
interface RpcClientOptions {
    /** List of server workers */
    workers: Worker[];
}
interface RpcEvent {
    /** Message event data */
    data: {
        /** Remote call uid */
        uid: string;
        /** `true` flag */
        libRpc: true;
        /** Error description */
        error?: string;
        /** Remote procedure name */
        method?: string;
        /** Server event name */
        eventName?: string;
        /** Procedure result or event data */
        data: any;
    };
}
interface RpcErrorEvent extends ErrorEvent {
    /** Error ignored if this is not true */
    libRpc?: boolean;
}
export default class RpcClient extends EventEmitter {
    workers: Worker[];
    protected idx: number;
    protected calls: Record<string, (data: any) => void>;
    protected timeouts: Record<string, NodeJS.Timeout>;
    protected errors: Record<string, (error: Error) => void>;
    /**
     * Client could be connected to several workers for better CPU utilization.
     * Requests are sent to an exact worker by round robin algorithm.
     * @param options - Rpc Client options
     */
    constructor({ workers }: RpcClientOptions);
    /**
     * Subscribtion to web workers events
     */
    protected init(): void;
    /**
     * Subsrciption to exact worker
     * @param worker - Server worker
     */
    protected listen(worker: Worker): void;
    /**
     * Message handler
     * @param e - Event object
     */
    protected handler(e: RpcEvent): void;
    /**
     * Error handler
     * https://www.nczonline.net/blog/2009/08/25/web-workers-errors-and-debugging/
     * @param options - Error handler options
     */
    catch({ message, lineno, filename, libRpc }: RpcErrorEvent): void;
    /**
     * Handle remote procedure call error
     * @param uid - Remote call uid
     * @param error - Error message
     */
    protected reject(uid: string, error: string | Error): void;
    /**
     * Handle remote procedure call response
     * @param uid - Remote call uid
     * @param data - Response data
     */
    protected resolve(uid: string, data: any): void;
    /**
     * Clear inner references to remote call
     * @param uid - Remote call uid
     */
    protected clear(uid: string): void;
    /**
     * Remote procedure call. Only ArrayBuffers will be transferred automatically (not TypedArrays).
     * Error would be thrown, if:
     * - it happened during procedure
     * - you try to call an unexisted procedure
     * - procedure execution takes more than timeout
     * @param method - Remote procedure name
     * @param data - Request data
     * @param options - Options
     * @returns Remote procedure promise
     */
    call(method: string, data: any, { timeout }?: any): Promise<unknown>;
}
export {};
