Skip to content

Commit

Permalink
Merge pull request #114 from Frans-Willem/develop
Browse files Browse the repository at this point in the history
Fix for reduction of future<future<void>> in case of exception.
  • Loading branch information
FelixPetriconi authored Dec 12, 2017
2 parents 757616f + 6cd28a9 commit 865c5e6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions stlab/concurrency/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ struct shared_base<T, enable_if_copyable<T>> : std::enable_shared_from_this<shar
template <typename R>
auto reduce(R&& r) {
return std::forward<R>(r);
};
}

auto reduce(future<future<void>>&& r) -> future<void>;

Expand Down Expand Up @@ -448,7 +448,7 @@ struct shared_base<T, enable_if_not_copyable<T>> : std::enable_shared_from_this<
template <typename R>
auto reduce(R&& r) {
return std::forward<R>(r);
};
}

template <typename R>
auto reduce(future<future<R>>&& r) -> future<R>;
Expand Down Expand Up @@ -537,7 +537,7 @@ struct shared_base<void> : std::enable_shared_from_this<shared_base<void>> {
template <typename R>
auto reduce(R&& r) {
return std::forward<R>(r);
};
}

auto reduce(future<future<void>>&& r) -> future<void>;

Expand Down Expand Up @@ -1574,7 +1574,15 @@ struct value_setter<T, enable_if_copyable<T>>

template <typename F, typename... Args>
static void set(shared_base<future<void>> &sb, F& f, Args&&... args) {
sb._result = f(std::forward<Args>(args)...).then([_p = sb.shared_from_this()]() {
sb._result = f(std::forward<Args>(args)...).recover([_p = sb.shared_from_this()](future<void> f) {
if (f.error())
{
_p->_error = std::move(f.error().value());
value_setter::proceed(*_p);
throw future_error(future_error_codes::reduction_failed);
}
return;
}).then([_p = sb.shared_from_this()]() {
proceed(*_p);
});
}
Expand Down

0 comments on commit 865c5e6

Please sign in to comment.