core: Fail do_until() future when the callback throws

Otherwise we will aband the result promise, which results in abort.
This commit is contained in:
Tomasz Grabiec
2015-02-10 13:14:23 +01:00
committed by Avi Kivity
parent ee58c77008
commit 331d5e1569

View File

@@ -38,17 +38,22 @@ template<typename AsyncAction, typename StopCondition>
static inline
void do_until_continued(StopCondition&& stop_cond, AsyncAction&& action, promise<> p) {
while (!stop_cond()) {
auto&& f = action();
if (!f.available()) {
f.then([action = std::forward<AsyncAction>(action),
try {
auto&& f = action();
if (!f.available()) {
f.then([action = std::forward<AsyncAction>(action),
stop_cond = std::forward<StopCondition>(stop_cond), p = std::move(p)]() mutable {
do_until_continued(stop_cond, std::forward<AsyncAction>(action), std::move(p));
});
return;
}
do_until_continued(stop_cond, std::forward<AsyncAction>(action), std::move(p));
});
return;
}
if (f.failed()) {
f.forward_to(std::move(p));
if (f.failed()) {
f.forward_to(std::move(p));
return;
}
} catch (...) {
p.set_exception(std::current_exception());
return;
}
}