25 namespace catapult {
namespace thread {
56 typename TContinuation,
57 typename TResultType = std::invoke_result_t<TContinuation, future<T>&&>
59 auto then(TContinuation continuation) {
60 if constexpr (!std::is_same_v<TResultType, void>) {
61 auto pResultState = std::make_shared<detail::shared_state<TResultType>>();
62 m_pState->set_continuation([pResultState, continuation](
const auto& pState) {
64 pResultState->set_value(continuation(
future<T>(pState)));
66 pResultState->set_exception(std::current_exception());
73 continuation(std::move(
future));
80 std::shared_ptr<detail::shared_state<T>>
m_pState;
89 :
m_pState(std::make_shared<detail::shared_state<T>>())
103 throw std::future_error(std::future_errc::future_already_retrieved);
111 m_pState->set_value(std::move(value));
116 m_pState->set_exception(pException);
127 auto pState = std::make_shared<detail::shared_state<T>>();
128 pState->set_value(std::move(value));
133 template<
typename T,
typename E>
135 auto pState = std::make_shared<detail::shared_state<T>>();
136 pState->set_exception(std::make_exception_ptr(ex));