Really fix the clang warning in Format-inl.h
[folly.git] / folly / wangle / Later.h
index 354f7d5a5614110af9bd64c6d605071458f9297e..329748e1e7a82af9d3cbec88ca9f41ac063d6ceb 100644 (file)
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include <folly/wangle/Deprecated.h>
 #include <folly/wangle/Executor.h>
 #include <folly/wangle/Future.h>
 #include <folly/Optional.h>
@@ -76,8 +77,10 @@ template <typename T> struct isLater;
  *   .then([=]Try<DiskResponse>&& t) { return sendClientResponse(t.value()); })
  *   .launch();
  */
+// DEPRECATED. Just use Future::via() to accomplish the same thing. If it's
+// not obvious how, feel free to reach out.
 template <class T>
-class Later {
+class DEPRECATED Later {
  public:
   typedef T value_type;
 
@@ -175,6 +178,27 @@ class Later {
     Later<typename std::result_of<F(Try<T>&&)>::type::value_type> >::type
   then(F&& fn);
 
+
+  /// Variant where func is an ordinary function (static method, method)
+  /// Must return a Later
+  template <class R>
+  typename std::enable_if<isLater<R>::value, R>::type
+  inline then(R(*func)(Try<T>&&)) {
+    return then([func](Try<T>&& t) {
+      return (*func)(std::move(t));
+    });
+  }
+
+  /// Variant where func is an member function
+  /// Must return a Later
+  template <class R, class Caller>
+  typename std::enable_if<isLater<R>::value, R>::type
+  inline then(Caller *instance, R(Caller::*func)(Try<T>&&)) {
+    return then([instance, func](Try<T>&& t) {
+      return (instance->*func)(std::move(t));
+    });
+  }
+
   /*
    * Resets the executor - all then() calls made after the call to via() will be
    * made in the new executor. The Executor must outlive.
@@ -189,11 +213,6 @@ class Later {
    */
   Future<T> launch();
 
-  /*
-   * Deprecated. Use launch()
-   */
-  void fireAndForget() __attribute__ ((deprecated)) { launch(); }
-
  private:
   Promise<void> starter_;
   folly::Optional<Future<T>> future_;
@@ -206,6 +225,10 @@ class Later {
   friend class Later;
 };
 
+// See Future.whenAll
+template <class T>
+Later<std::vector<Try<T>>> whenAllLater(std::vector<Later<T>>&& laters);
+
 }}
 
-#include "Later-inl.h"
+#include <folly/wangle/Later-inl.h>