UNPKG

@averagehelper/corde

Version:

A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)

70 lines (69 loc) 2.61 kB
/** * Structure to handle a collection of functions and execute then. * This structure does not remove its values after its executions. */ export declare class Queue<T extends (...args: any[]) => any> { private readonly _funcs; private readonly _defaultParameters; /** * Gets default parameters added. */ get defaultParameters(): Parameters<T>[]; constructor(); /** * Add a function to queue. * * @param fn Functions to be queued */ enqueue(fn: T): string; /** * Removes a function from queue * @param fn Function to be removed from queue. */ dequeue(guid: string): boolean; /** * Execute functions with parameters. * @param params Parameters to be injected on function in queue. */ executeAsync<K extends Parameters<T>, U extends ReturnType<T>>(...params: K): Promise<U[]>; /** * Execute functions with parameters. * @param params Parameters to be injected on function in queue. */ executeSync<K extends Parameters<T>, U extends ReturnType<T>>(...params: K): U[]; /** * Execute function with exception treatment. * So if any function throw a error, it will be handled by an catch function * provided in parameters. * @param catchAction Function to handle errors. * @param params Parameters to the functions. */ tryExecuteSync<K extends Parameters<T>, U extends ReturnType<T>>(catchAction?: (error: any) => any, ...params: K): U[]; /** * Execute function with exception treatment. * So if any function throw a error, it will be handled by an catch function * provided in parameters. * @param catchAction Function to handle errors. * @param params Parameters to the functions. */ tryExecuteAsync<K extends Parameters<T>, U extends ReturnType<T>>(catchAction?: (error: any) => any, ...params: K): Promise<U[]>; /** * Function like *tryExecute()* but return all exceptions if they * occur. * @param params Parameters to the functions. */ executeWithCatchCollectSync<K extends Parameters<T>>(...params: K): any[]; /** * Function like *tryExecute()* but return all exceptions if they * occur. * @param params Parameters to the functions. */ executeWithCatchCollectAsync<K extends Parameters<T>>(...params: K): Promise<any[]>; /** * Add parameters to be injected on queued functions * @param parameter Parameter value */ addDefaultParameters<K extends Parameters<T>>(...parameter: K): void; size(): number; clear(): void; }