void retryingImpl(size_t k, Policy&& p, FF&& ff, Prom prom) {
using F = typename std::result_of<FF(size_t)>::type;
using T = typename F::value_type;
- auto f = ff(k++);
+ auto f = makeFutureWith([&] { return ff(k++); });
f.then([
k,
prom = std::move(prom),
EXPECT_EQ(2, r.value());
}
+TEST(RetryingTest, future_factory_throws) {
+ struct ReturnedException : exception {};
+ struct ThrownException : exception {};
+ auto result = futures::retrying(
+ [](size_t n, const exception_wrapper&) { return n < 2; },
+ [](size_t n) {
+ switch (n) {
+ case 0:
+ return makeFuture<size_t>(
+ make_exception_wrapper<ReturnedException>());
+ case 1:
+ throw ThrownException();
+ default:
+ return makeFuture(n);
+ }
+ })
+ .wait()
+ .getTry();
+ EXPECT_THROW(result.throwIfFailed(), ThrownException);
+}
+
TEST(RetryingTest, policy_future) {
atomic<size_t> sleeps {0};
auto r = futures::retrying(