UNPKG

@applitools/eyes-storybook

Version:
23 lines (17 loc) 598 B
const {delay, ptimeoutWithFunction} = require('@applitools/functional-commons'); async function executeWithRetry(fn, {timeout, initialErrMessage, delayBetweenRetries}) { let err = new Error(initialErrMessage); return ptimeoutWithFunction(_executeWithRetry, timeout, () => Promise.reject(err)); async function _executeWithRetry(hasAborted) { try { return await fn(); } catch (fnErr) { err = fnErr; } if (!hasAborted()) { await delay(delayBetweenRetries); return await _executeWithRetry(hasAborted); } } } module.exports = {executeWithRetry};