#pragma once
+#include <folly/wangle/Deprecated.h>
#include <folly/wangle/Executor.h>
#include <folly/wangle/Future.h>
#include <folly/Optional.h>
* .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;
class = typename std::enable_if<std::is_same<T, U>::value>::type>
explicit Later(U&& input);
+ /*
+ * This constructor is used to build an asynchronous workflow that takes an
+ * exception_ptr as input, and throws it on completion.
+ */
+ explicit Later(std::exception_ptr const&);
+
+ /*
+ * This constructor is used to build an asynchronous workflow that takes an
+ * exception as input, and throws it on completion.
+ */
+ template <class E,
+ class = typename std::enable_if<
+ std::is_base_of<std::exception, E>::value>::type>
+ explicit Later(E const& e);
+
/*
* This constructor is used to wrap a pre-existing cob-style asynchronous api
* so that it can be used in wangle. wangle provides the callback to this
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.
*/
Future<T> launch();
- /*
- * Deprecated. Use launch()
- */
- void fireAndForget() __attribute__ ((deprecated)) { launch(); }
-
private:
Promise<void> starter_;
folly::Optional<Future<T>> future_;
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>