1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00
metamask-extension/development/lib/retry.js
Mark Stacey cc90fca2f6
Add retries to the benchmark script (#11319)
The benchmark script can now be set to retry upon failure, like the E2E
tests do. The default is zero, just as with the E2E tests. A retry of 2
has been set in CI to match the E2E tests as well.

The `retry` module had to be adjusted to throw an error in the case of
failure. Previously it just set the exit code, but that only worked
because it was the last thing called before the process ended. That is
no longer the case.
2021-06-21 12:46:18 -02:30

24 lines
603 B
JavaScript

/**
* Run the given function, retrying it upon failure until reaching the
* specified number of retries.
*
* @param {number} retries - The number of retries upon failure to attempt.
* @param {function} functionToRetry - The function that will be retried upon failure.
*/
async function retry(retries, functionToRetry) {
let attempts = 0;
while (attempts <= retries) {
try {
await functionToRetry();
return;
} catch (error) {
console.error(error);
} finally {
attempts += 1;
}
}
throw new Error('Retry limit reached');
}
module.exports = { retry };