retryStrategy.js 760 B

1234567891011121314151617181920
  1. /**
  2. * Class used to define a retry strategy when error happens while loading assets
  3. */
  4. export class RetryStrategy {
  5. /**
  6. * Function used to defines an exponential back off strategy
  7. * @param maxRetries defines the maximum number of retries (3 by default)
  8. * @param baseInterval defines the interval between retries
  9. * @returns the strategy function to use
  10. */
  11. static ExponentialBackoff(maxRetries = 3, baseInterval = 500) {
  12. return (url, request, retryIndex) => {
  13. if (request.status !== 0 || retryIndex >= maxRetries || url.indexOf("file:") !== -1) {
  14. return -1;
  15. }
  16. return Math.pow(2, retryIndex) * baseInterval;
  17. };
  18. }
  19. }
  20. //# sourceMappingURL=retryStrategy.js.map