Commit 1d3ee8c5 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Fix for lifetime bug in retrying.

Summary: Late change in D9175807 removed necessary temporaries. This caused a lifetime management problem for GCC.

Reviewed By: Orvid

Differential Revision: D9227937

fbshipit-source-id: d5fea8a98855c6302189a7dee8cd5862d13a63a3
parent 7ef79a5f
......@@ -83,31 +83,31 @@ template <class Policy, class FF, class Prom>
void retryingImpl(size_t k, Policy&& p, FF&& ff, Prom prom) {
using F = invoke_result_t<FF, size_t>;
using T = typename F::value_type;
makeFutureWith([&] { return ff(k++); })
.then([k,
prom = std::move(prom),
pm = std::forward<Policy>(p),
ffm = std::forward<FF>(ff)](Try<T>&& t) mutable {
if (t.hasValue()) {
prom.setValue(std::move(t).value());
return;
}
auto& x = t.exception();
makeFutureWith([&] { return pm(k, x); })
.then([k,
prom = std::move(prom),
xm = std::move(x),
pm = std::move(pm),
ffm = std::move(ffm)](Try<bool> shouldRetry) mutable {
if (shouldRetry.hasValue() && shouldRetry.value()) {
retryingImpl(k, std::move(pm), std::move(ffm), std::move(prom));
} else if (shouldRetry.hasValue()) {
prom.setException(std::move(xm));
} else {
prom.setException(std::move(shouldRetry.exception()));
}
});
});
auto f = makeFutureWith([&] { return ff(k++); });
f.then([k,
prom = std::move(prom),
pm = std::forward<Policy>(p),
ffm = std::forward<FF>(ff)](Try<T>&& t) mutable {
if (t.hasValue()) {
prom.setValue(std::move(t).value());
return;
}
auto& x = t.exception();
auto q = makeFutureWith([&] { return pm(k, x); });
q.then([k,
prom = std::move(prom),
xm = std::move(x),
pm = std::move(pm),
ffm = std::move(ffm)](Try<bool> shouldRetry) mutable {
if (shouldRetry.hasValue() && shouldRetry.value()) {
retryingImpl(k, std::move(pm), std::move(ffm), std::move(prom));
} else if (shouldRetry.hasValue()) {
prom.setException(std::move(xm));
} else {
prom.setException(std::move(shouldRetry.exception()));
}
});
});
}
template <class Policy, class FF>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment