retrier.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * A class that manages a queue of retry jobs.
  3. */
  4. export class Retrier {
  5. /**
  6. * Creates a new instance.
  7. * @param {Function} check The function to call.
  8. * @param {object} [options] The options for the instance.
  9. * @param {number} [options.timeout] The timeout for the queue.
  10. * @param {number} [options.maxDelay] The maximum delay for the queue.
  11. * @param {number} [options.concurrency] The maximum number of concurrent tasks.
  12. */
  13. constructor(check: Function, { timeout, maxDelay, concurrency }?: {
  14. timeout?: number | undefined;
  15. maxDelay?: number | undefined;
  16. concurrency?: number | undefined;
  17. } | undefined);
  18. /**
  19. * Gets the number of tasks waiting to be retried.
  20. * @returns {number} The number of tasks in the retry queue.
  21. */
  22. get retrying(): number;
  23. /**
  24. * Gets the number of tasks waiting to be processed in the pending queue.
  25. * @returns {number} The number of tasks in the pending queue.
  26. */
  27. get pending(): number;
  28. /**
  29. * Gets the number of tasks currently being processed.
  30. * @returns {number} The number of tasks currently being processed.
  31. */
  32. get working(): number;
  33. /**
  34. * Adds a new retry job to the queue.
  35. * @param {Function} fn The function to call.
  36. * @param {object} [options] The options for the job.
  37. * @param {AbortSignal} [options.signal] The AbortSignal to monitor for cancellation.
  38. * @returns {Promise<any>} A promise that resolves when the queue is
  39. * processed.
  40. */
  41. retry(fn: Function, { signal }?: {
  42. signal?: AbortSignal | undefined;
  43. } | undefined): Promise<any>;
  44. #private;
  45. }