Track absolute position of the cursor
[folly.git] / folly / futures / SharedPromise.h
index 0c8fcd9a747d86e59f132d1c9f2b72824b30b1f5..c8c77ccdfaa294c2fc5404e4b8e5edf8526ab4c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <folly/Portability.h>
+#include <folly/executors/InlineExecutor.h>
 #include <folly/futures/Promise.h>
 
 namespace folly {
@@ -33,7 +35,7 @@ namespace folly {
  */
 template <class T>
 class SharedPromise {
-public:
+ public:
   SharedPromise() = default;
   ~SharedPromise() = default;
 
@@ -49,6 +51,15 @@ public:
    * Return a Future tied to the shared core state. Unlike Promise::getFuture,
    * this can be called an unlimited number of times per SharedPromise.
    */
+  SemiFuture<T> getSemiFuture();
+
+  /**
+   * Return a Future tied to the shared core state. Unlike Promise::getFuture,
+   * this can be called an unlimited number of times per SharedPromise.
+   * NOTE: This function is deprecated. Please use getSemiFuture and pass the
+   *       appropriate executor to .via on the returned SemiFuture to get a
+   *       valid Future where necessary.
+   */
   Future<T> getFuture();
 
   /** Return the number of Futures associated with this SharedPromise */
@@ -64,7 +75,8 @@ public:
       p.setException(std::current_exception());
     }
     */
-  void setException(std::exception_ptr const&) DEPRECATED;
+  FOLLY_DEPRECATED("use setException(exception_wrapper)")
+  void setException(std::exception_ptr const&);
 
   /** Fulfill the SharedPromise with an exception type E, which can be passed to
     std::make_exception_ptr(). Useful for originating exceptions. If you
@@ -81,13 +93,6 @@ public:
   /// handled.
   void setInterruptHandler(std::function<void(exception_wrapper const&)>);
 
-  /// Fulfill this SharedPromise<void>
-  template <class B = T>
-  typename std::enable_if<std::is_void<B>::value, void>::type
-  setValue() {
-    setTry(Try<T>());
-  }
-
   /// Sugar to fulfill this SharedPromise<Unit>
   template <class B = T>
   typename std::enable_if<std::is_same<Unit, B>::value, void>::type
@@ -110,15 +115,18 @@ public:
   template <class F>
   void setWith(F&& func);
 
-private:
+  bool isFulfilled();
+
+ private:
   std::mutex mutex_;
   size_t size_{0};
   bool hasValue_{false};
   Try<T> try_;
   std::vector<Promise<T>> promises_;
+  std::function<void(exception_wrapper const&)> interruptHandler_;
 };
 
-}
+} // namespace folly
 
 #include <folly/futures/Future.h>
 #include <folly/futures/SharedPromise-inl.h>