#pragma once
-#include "folly/wangle/Executor.h"
-#include "folly/wangle/Future.h"
-#include "folly/Optional.h"
+#include <folly/wangle/Executor.h>
+#include <folly/wangle/Future.h>
+#include <folly/Optional.h>
namespace folly { namespace wangle {
future_ = starter_.getFuture();
}
+template <class T>
+Later<T>::Later(Future<T>&& f) {
+ MoveWrapper<Future<T>> fw(std::move(f));
+ *this = Later<void>()
+ .then([fw](Try<void>&&) mutable {
+ return std::move(*fw);
+ });
+}
+
template <typename T>
Later<T>::Later(Promise<void>&& starter)
: starter_(std::forward<Promise<void>>(starter)) { }
template <class T>
Later<T> Later<T>::via(Executor* executor) {
- Promise<T> promise;
+ folly::MoveWrapper<Promise<T>> promise;
Later<T> later(std::move(starter_));
- later.future_ = promise.getFuture();
- future_->executeWith(executor, std::move(promise));
+ later.future_ = promise->getFuture();
+
+ future_->setCallback_([executor, promise](Try<T>&& t) mutable {
+ folly::MoveWrapper<Try<T>> tt(std::move(t));
+ executor->add([promise, tt]() mutable {
+ promise->fulfilTry(std::move(*tt));
+ });
+ });
+
return later;
}