aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/retry.h
blob: aa8391fa48dc0a4ba1f55b990b505d7ea707d8d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once

namespace NYql {

template <typename TRetriableException, typename TAction, typename TExceptionHandler>
auto WithRetry(int attempts, TAction&& a, TExceptionHandler&& exceptionHandler) {
    for (int i = 1; i < attempts; ++i) {
        try {
            return a();
        } catch (const TRetriableException& e) {
            exceptionHandler(e, i, attempts);
        }
    }

    return a();
}
}