summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/retry.h
blob: ab6d9bf809a67b6cad419d2a040c5638b446697e (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();
}
} // namespace NYql