retry.h 411 B

1234567891011121314151617
  1. #pragma once
  2. namespace NYql {
  3. template <typename TRetriableException, typename TAction, typename TExceptionHandler>
  4. auto WithRetry(int attempts, TAction&& a, TExceptionHandler&& exceptionHandler) {
  5. for (int i = 1; i < attempts; ++i) {
  6. try {
  7. return a();
  8. } catch (const TRetriableException& e) {
  9. exceptionHandler(e, i, attempts);
  10. }
  11. }
  12. return a();
  13. }
  14. }