retry.js 526 B

1234567891011121314151617181920212223
  1. function runWithRetry(callback, maxRetries) {
  2. function executeWithRetryAndTimeout(currentCount) {
  3. try {
  4. if (currentCount > maxRetries - 1) {
  5. console.warn('[React Refresh] Failed to set up the socket connection.');
  6. return;
  7. }
  8. callback();
  9. } catch (err) {
  10. setTimeout(
  11. function () {
  12. executeWithRetryAndTimeout(currentCount + 1);
  13. },
  14. Math.pow(10, currentCount)
  15. );
  16. }
  17. }
  18. executeWithRetryAndTimeout(0);
  19. }
  20. module.exports = runWithRetry;