From 4b10441e5c2e76394bcfc7e06e4326d136d0114b Mon Sep 17 00:00:00 2001 From: Vladyslav Zubko <42296182+what1s1ove@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:56:08 +0300 Subject: [PATCH] refactor(shared): edit retryCall function signature wd-676 (#712) --- apps/whatislove-dev/src/data/mentions.js | 3 +-- .../libs/helpers/retry-call/retry-call.helper.js | 15 ++++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/whatislove-dev/src/data/mentions.js b/apps/whatislove-dev/src/data/mentions.js index eda04ec6..960f5d62 100644 --- a/apps/whatislove-dev/src/data/mentions.js +++ b/apps/whatislove-dev/src/data/mentions.js @@ -271,8 +271,7 @@ let loader = async () => { let allPagesMentions = /** @type {PagesMentions} */ ({}) for (let mentionLoader of mentionLoaders) { - let fetchedPageMentions = await retryCall({ - callback: mentionLoader, + let fetchedPageMentions = await retryCall(mentionLoader, { retriesCount: 3, }) diff --git a/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js b/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js index 37dba8fb..b2ab3238 100644 --- a/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js +++ b/packages/shared/src/libs/helpers/retry-call/retry-call.helper.js @@ -5,20 +5,18 @@ let RETRY_COUNT_DECREMENT_PER_CALL = /** @type {const} */ (1) /** * @template {unknown} T + * @param {(...args: unknown[]) => T | Promise} callback * @param {{ - * callback: (...args: unknown[]) => T | Promise * retriesCount?: number * delayMs?: number * delayFactorCount?: number - * }} params + * }} [options] * @returns {Promise} */ -let retryCall = async ({ +let retryCall = async ( callback, - delayFactorCount = 3, - delayMs = 1000, - retriesCount = 3, -}) => { + { delayFactorCount = 3, delayMs = 1000, retriesCount = 3 } = {}, +) => { try { return await callback() } catch (error) { @@ -33,8 +31,7 @@ let retryCall = async ({ let updatedDelayMs = delayMs * delayFactorCount let updatedTriesCount = retriesCount - RETRY_COUNT_DECREMENT_PER_CALL - return retryCall({ - callback, + return retryCall(callback, { delayFactorCount, delayMs: updatedDelayMs, retriesCount: updatedTriesCount,