import { IRCMessage } from "../message/irc/irc-message.mjs";
import { SingleConnection } from "../client/connection.mjs";
//#region src/await/await-response.d.ts
type Condition = (message: IRCMessage) => boolean;
type NoResponseAction = "success" | "failure";
interface AwaitConfig {
/**
* If this condition evaluates to true on any incoming message, the promise is resolved with the message
* that matched.
*/
success?: Condition;
/**
* If this condition evaluates to true on any incoming message, the promise is rejected with an
* error specifying the cause message.
*/
failure?: Condition;
/**
* If neither the success or failure condition match on any message within
* this period (after connection, {@link noResponseAction} is taken.
*/
timeout?: number;
/**
* Action to take after
* - a timeout occurs or
* - a response awaited later than this response is resolved or rejected
* (and given that since the server processes commands
* and sends their responses strictly sequentially) this response would
* never be fulfilled because the server is done processing this command
*
* E.g. the client issues JOIN #a,#b,#c to the server,
* and receives the responses for a and c,
* in that order. In that case, the response for b can be
* rejected the moment the response for c is received.
*/
noResponseAction?: NoResponseAction;
/**
* Function to create custom error type given optional message and
* cause error.
*
* @param message Optional message
* @param cause Optional cause
*/
errorType: (message: string, cause?: Error) => Error;
/**
* Custom error message to pass to the {@link errorType} function
* as the message, preferably about what kind of response to what
* input variables was awaited (e.g. channel name)
*/
errorMessage: string;
}
declare class ResponseAwaiter {
readonly promise: Promise;
private readonly unsubscribers;
private readonly conn;
private readonly config;
private resolvePromise;
private rejectPromise;
constructor(conn: SingleConnection, config: AwaitConfig);
/**
* Called when this response awaiter is inserted to the head of
* the queue or moves to the queue head after a previous
* response awaiter was rejected or resolved.
*/
movedToQueueHead(): void;
/**
* Called by a later awaiter indicating that this awaiter was still
* in the queue while the later awaiter matched a response.
*/
outpaced(): void;
private unsubscribe;
private resolve;
private reject;
private onNoResponse;
private beginTimeout;
private joinPendingResponsesQueue;
private onConnectionClosed;
onConnectionMessage(message: IRCMessage): boolean;
private subscribeTo;
}
declare function awaitResponse(conn: SingleConnection, config: AwaitConfig & {
noResponseAction?: TNoResponseAction;
success?: ((message: IRCMessage) => message is TMessage) | Condition;
}): Promise;
//#endregion
export { AwaitConfig, Condition, NoResponseAction, ResponseAwaiter, awaitResponse };
//# sourceMappingURL=await-response.d.mts.map