Codemod: use #include angle brackets in folly and thrift
[folly.git] / folly / wangle / Later-inl.h
index aaba5c94395d79be032a16dbe2ad6ee7e6839628..c92ceb55f8267f536eafe7e393b31a0655e6a79e 100644 (file)
@@ -16,9 +16,9 @@
 
 #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 {
 
@@ -53,6 +53,15 @@ Later<T>::Later() {
   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)) { }
@@ -130,10 +139,17 @@ Later<T>::then(F&& fn) {
 
 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;
 }