@fivem-ts/shared
Version:
FiveM Typescript wrapper shared part
54 lines (53 loc) • 1.85 kB
TypeScript
import 'reflect-metadata';
import { Maybe } from '../../@types';
export type RetryValue = {
attempts: number;
delay: number;
};
/**
* A decorator to automatically retry a method upon failure.
*
* This decorator retries the decorated method a specified number of times, with a delay between each attempt.
* If all attempts fail, the last error will be thrown.
*
* @example
* ```ts
* import { Retry } from 'fivem-ts/shared/decorators';
*
* class MyService {
* @Retry(3, 1000)
* async unstableMethod(): Promise<void> {
* // Some operation that might fail
* }
* }
* ```
*
* @param attempts The number of retry attempts before failing.
* @param delay The delay in milliseconds between each retry attempt.
*
* @returns A method decorator that applies the retry logic.
*/
export declare function Retry(attempts: number, delay: number): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<Function>) => void;
/**
* Retrieves the retry metadata for a given method.
*
* This function can be used to obtain the number of retry attempts and the delay between attempts
* for a method decorated with the `Retry` decorator.
*
* @example
*
* ```ts
* import { getRetryMetadata } from 'fivem-ts/shared/decorators';
*
* const retryMetadata = getRetryMetadata(MyService.prototype, 'unstableMethod');
* if (retryMetadata) {
* console.log(`Retry attempts: ${retryMetadata.attempts}, Delay: ${retryMetadata.delay}`);
* }
* ```
*
* @param target The target object (usually the prototype of a class).
* @param propertyKey The name of the method to retrieve metadata for.
*
* @returns An object containing the number of attempts and the delay, or `undefined` if not found.
*/
export declare function getRetryMetadata(target: object, propertyKey: string): Maybe<RetryValue>;