@geniucode/common-utils
Version:
Common utils
33 lines • 1 kB
JavaScript
export const runWithRetry = async (fcn, retries, path, condition, ...args) => {
let result = null;
do {
try {
result = await fcn(...args);
}
catch (err) { }
retries--;
} while (convertPathToDotFormat(result, path) !== condition && retries > 0);
return result;
};
export const runWithRetryIgnoreCondition = async (fcn, retries, ...args) => {
let result = null;
do {
try {
result = await fcn(...args);
}
catch (err) { }
retries--;
} while (retries > 0);
return result;
};
export const convertPathToDotFormat = (obj, is, value) => {
if (typeof is == 'string')
return convertPathToDotFormat(obj, is.split('.'), value);
else if (is.length == 1 && value !== undefined)
return (obj[is[0]] = value);
else if (is.length == 0)
return obj;
else
return convertPathToDotFormat(obj[is[0]], is.slice(1), value);
};
//# sourceMappingURL=retries.js.map