@parzh/retryable
Version:
Convenience function to retry an action
27 lines (26 loc) • 694 B
TypeScript
import type Action from "./typings/action";
/**
* Retry action
* @param action Action to perform an retry if needed
* @example
* const content = await retryable((resolve, reject, retry) => {
* fs.readfile("/path/to/file", (err, data) => {
* if (!err)
* return resolve(data);
*
* if (retry.count >= RETRY_LIMIT)
* if (SHOULD_IGNORE_RETRY_LIMIT)
* retry.setCount(0);
*
* else
* return reject("Retry limit reached!");
*
* if (SHOULD_RETRY_IMMEDIATELY)
* retry();
*
* else
* retry.after("exponential");
* });
* });
*/
export default function retryable<Value = unknown>(action: Action<Value>): Promise<Value>;