}
template <class T>
-Future<T> SharedPromise<T>::getFuture() {
+SemiFuture<T> SharedPromise<T>::getSemiFuture() {
std::lock_guard<std::mutex> g(mutex_);
size_++;
if (hasValue_) {
if (interruptHandler_) {
promises_.back().setInterruptHandler(interruptHandler_);
}
- return promises_.back().getFuture();
+ return promises_.back().getSemiFuture();
}
}
+template <class T>
+Future<T> SharedPromise<T>::getFuture() {
+ return getSemiFuture().via(&folly::InlineExecutor::instance());
+}
+
template <class T>
template <class E>
typename std::enable_if<std::is_base_of<std::exception, E>::value>::type
#pragma once
#include <folly/Portability.h>
+#include <folly/executors/InlineExecutor.h>
#include <folly/futures/Promise.h>
namespace folly {
* 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 */
using namespace folly;
+TEST(SharedPromise, setGetSemiFuture) {
+ SharedPromise<int> p;
+ p.setValue(1);
+ auto f1 = p.getSemiFuture();
+ auto f2 = p.getSemiFuture();
+ EXPECT_EQ(1, f1.value());
+ EXPECT_EQ(1, f2.value());
+}
+
+TEST(SharedPromise, setGetMixed) {
+ SharedPromise<int> p;
+ p.setValue(1);
+ auto f1 = p.getSemiFuture();
+ auto f2 = p.getFuture();
+ EXPECT_EQ(1, f1.value());
+ EXPECT_EQ(1, f2.value());
+}
+
TEST(SharedPromise, setGet) {
SharedPromise<int> p;
p.setValue(1);