+ /** Attach a continuation to this future
+ *
+ * This is like .then() but avoid the creation of a new future.
+ */
+ template<class F>
+ void then_(F continuation)
+ {
+ if (state_ == nullptr)
+ throw std::future_error(std::future_errc::no_state);
+ // Give shared-ownership to the continuation:
+ auto state = std::move(state_);
+ state->set_continuation(simgrid::xbt::makeTask(
+ std::move(continuation), state));
+ }
+
+ /** Attach a continuation to this future
+ *
+ * This version never does future unwrapping.
+ */
+ template<class F>
+ auto thenNoUnwrap(F continuation)
+ -> Future<decltype(continuation(std::move(*this)))>
+ {
+ typedef decltype(continuation(std::move(*this))) R;
+ if (state_ == nullptr)
+ throw std::future_error(std::future_errc::no_state);
+ auto state = std::move(state_);
+ // Create a new future...
+ Promise<R> promise;
+ Future<R> future = promise.get_future();
+ // ...and when the current future is ready...
+ state->set_continuation(simgrid::xbt::makeTask(
+ [](Promise<R> promise, std::shared_ptr<FutureState<T>> state, F continuation) {
+ // ...set the new future value by running the continuation.
+ Future<T> future(std::move(state));
+ simgrid::xbt::fulfillPromise(promise,[&]{
+ return continuation(std::move(future));
+ });
+ },
+ std::move(promise), state, std::move(continuation)));
+ return std::move(future);
+ }
+