Don't require folly::Unit in addTaskFinally
authorAndrii Grynenko <andrii@fb.com>
Sat, 30 Apr 2016 00:50:50 +0000 (17:50 -0700)
committerFacebook Github Bot 8 <facebook-github-bot-8-bot@fb.com>
Sat, 30 Apr 2016 01:05:24 +0000 (18:05 -0700)
Summary:
In D3241498 addTaskFuture was fixed to work with function returning void. This however changed addTaskFinally API to not allow finally functor which accepts Try<void>.

folly::fibers generally supports Try<void> so there's no reason to force users to use folly::Unit instead of void for addTaskFinally too.

Reviewed By: yfeldblum

Differential Revision: D3243893

fb-gh-sync-id: d1df54738157d2019120103956f59b3971ba25ff
fbshipit-source-id: d1df54738157d2019120103956f59b3971ba25ff

folly/experimental/fibers/FiberManager-inl.h
folly/futures/Try.h

index 8f31ede10d53348f6c50eef18d30bc9b2f3c75b8..1e91a5a6b7dc5912aec630a4b811e26e3901c090 100644 (file)
@@ -283,9 +283,10 @@ void FiberManager::addTask(F&& func) {
 template <typename F>
 auto FiberManager::addTaskFuture(F&& func) -> folly::Future<
     typename folly::Unit::Lift<typename std::result_of<F()>::type>::type> {
 template <typename F>
 auto FiberManager::addTaskFuture(F&& func) -> folly::Future<
     typename folly::Unit::Lift<typename std::result_of<F()>::type>::type> {
-  using T =
-      typename folly::Unit::Lift<typename std::result_of<F()>::type>::type;
-  folly::Promise<T> p;
+  using T = typename std::result_of<F()>::type;
+  using FutureT = typename folly::Unit::Lift<T>::type;
+
+  folly::Promise<FutureT> p;
   auto f = p.getFuture();
   addTaskFinally(
       [func = std::forward<F>(func)]() mutable { return func(); },
   auto f = p.getFuture();
   addTaskFinally(
       [func = std::forward<F>(func)]() mutable { return func(); },
@@ -398,8 +399,7 @@ struct FiberManager::AddTaskFinallyHelper {
 
 template <typename F, typename G>
 void FiberManager::addTaskFinally(F&& func, G&& finally) {
 
 template <typename F, typename G>
 void FiberManager::addTaskFinally(F&& func, G&& finally) {
-  typedef typename folly::Unit::Lift<typename std::result_of<F()>::type>::type
-      Result;
+  typedef typename std::result_of<F()>::type Result;
 
   static_assert(
       IsRvalueRefTry<typename FirstArgOf<G>::type>::value,
 
   static_assert(
       IsRvalueRefTry<typename FirstArgOf<G>::type>::value,
index b4152dd46c2c796559f62d42c19e034d73c8feaf..5fae57f57295e24e4abf9f15bffea094620bf512 100644 (file)
@@ -244,6 +244,11 @@ class Try {
 template <>
 class Try<void> {
  public:
 template <>
 class Try<void> {
  public:
+  /*
+   * The value type for the Try
+   */
+  typedef void element_type;
+
   // Construct a Try holding a successful and void result
   Try() : hasValue_(true) {}
 
   // Construct a Try holding a successful and void result
   Try() : hasValue_(true) {}