staleElementWrapper<T> function

T staleElementWrapper<T>(
  1. MethodToRetry<T> method,
  2. ClearCacheMethod clear,
  3. IsStaleException isStaleException
)

Retries method if an exception is thrown and isStaleException is true for said exception.

Implementation

T staleElementWrapper<T>(MethodToRetry<T> method, ClearCacheMethod clear,
    IsStaleException isStaleException) {
  try {
    return method();
  } catch (e) {
    if (isStaleException(e)) {
      clear();
      return method();
    }

    rethrow;
  }
}