Skip to content

Commit

Permalink
refactor(shared): edit retryCall function signature wd-676 (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
what1s1ove authored Oct 7, 2024
1 parent 3bc80ab commit 4b10441
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions apps/whatislove-dev/src/data/mentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
15 changes: 6 additions & 9 deletions packages/shared/src/libs/helpers/retry-call/retry-call.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ let RETRY_COUNT_DECREMENT_PER_CALL = /** @type {const} */ (1)

/**
* @template {unknown} T
* @param {(...args: unknown[]) => T | Promise<T>} callback
* @param {{
* callback: (...args: unknown[]) => T | Promise<T>
* retriesCount?: number
* delayMs?: number
* delayFactorCount?: number
* }} params
* }} [options]
* @returns {Promise<T>}
*/
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) {
Expand All @@ -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,
Expand Down

0 comments on commit 4b10441

Please sign in to comment.