27 namespace catapult {
namespace thread {
35 #define INNER_STRUCT_VISIBILILTY __attribute__ ((visibility ("hidden")))
37 #define INNER_STRUCT_VISIBILILTY
45 explicit ContinuationContext(
size_t numFutures) : m_futures(numFutures), m_counter(0)
50 return m_jointPromise.get_future();
53 void setContinuation(FutureType&
future,
size_t index) {
54 auto pThis = this->shared_from_this();
55 future.
then([pThis, index](
auto&& continuationFuture) {
56 auto& futures = pThis->m_futures;
57 futures[index] = std::move(continuationFuture);
58 if (futures.size() != ++pThis->m_counter)
61 pThis->m_jointPromise.set_value(std::move(futures));
66 std::vector<FutureType> m_futures;
67 JointPromiseType m_jointPromise;
68 std::atomic<size_t> m_counter;
71 if (allFutures.empty())
75 auto pContext = std::make_shared<ContinuationContext>(allFutures.size());
76 for (
auto&
future : allFutures)
77 pContext->setContinuation(
future, i++);
79 return pContext->future();
81 #undef INNER_STRUCT_VISIBILILTY
87 std::vector<future<T>> futures;
88 futures.push_back(std::move(future1));
89 futures.push_back(std::move(future2));
99 typename TCreateNextFuture,
100 typename TResultFuture = std::invoke_result_t<TCreateNextFuture, future<TSeed>&&>,
101 typename TResultType = decltype(TResultFuture().get())>
103 auto pComposePromise = std::make_shared<promise<TResultType>>();
104 startFuture.then([createNextFuture, pComposePromise](
auto&& completedFirstFuture) {
106 auto secondFuture = createNextFuture(std::move(completedFirstFuture));
107 secondFuture.then([pComposePromise](
auto&& completedSecondFuture) {
109 pComposePromise->set_value(completedSecondFuture.get());
111 pComposePromise->set_exception(std::current_exception());
115 pComposePromise->set_exception(std::current_exception());
119 return pComposePromise->get_future();
126 std::vector<T> results;
127 for (
auto&
future : futures) {
142 std::vector<T> results;
143 for (
auto&
future : futures)