Skip to content

Commit

Permalink
Fix issue stlab#229
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixPetriconi committed Jan 27, 2019
1 parent 66522c9 commit ebf9428
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion stlab/concurrency/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#endif

#ifndef STLAB_CPP_VERSION
#define STLAB_CPP_VERSION 14
#define STLAB_CPP_VERSION 17
#endif

#ifndef STLAB_FUTURE_COROUTINES
Expand Down
26 changes: 14 additions & 12 deletions stlab/concurrency/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,16 +1683,18 @@ struct value_<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)...)
.recover([_p = sb.shared_from_this()](future<void> f) {
if (f.error()) {
_p->_error = std::move(*f.error());
value_::proceed(*_p);
throw future_error(future_error_codes::reduction_failed);
}
return;
})
.then([_p = sb.shared_from_this()]() { proceed(*_p); });
sb._result = f(std::forward<Args>(args)...);
sb._reduction_helper.value =
(*sb._result)
.recover([_p = sb.shared_from_this()](future<void> f) {
if (f.error()) {
_p->_error = std::move(*f.error());
value_::proceed(*_p);
throw future_error(future_error_codes::reduction_failed);
}
return;
})
.then([_p = sb.shared_from_this()]() { proceed(*_p); });
}
};

Expand Down Expand Up @@ -1810,13 +1812,13 @@ auto shared_base<T, enable_if_copyable<T>>::reduce(future<future<R>>&& r) -> fut

template <typename T>
auto shared_base<T, enable_if_not_copyable<T>>::reduce(future<future<void>>&& r) -> future<void> {
return std::move(r).then([](auto&&){});
return std::move(r).then([](auto){});
}

template <typename T>
template <typename R>
auto shared_base<T, enable_if_not_copyable<T>>::reduce(future<future<R>>&& r) -> future<R> {
return std::move(r).then([](auto&& f) { return *std::forward<future<R>>(f).get_try(); });
return std::move(r).then([](auto&& f) { return *std::move(f).get_try(); });
}

/**************************************************************************************************/
Expand Down

0 comments on commit ebf9428

Please sign in to comment.