Refactors folly sync test cases
[folly.git] / folly / futures / SharedPromise-inl.h
index 185062acdbcc01afbc5fd19ee543dadcc06a4b06..78c72430d4a6f694bc3f4f6e72dcb3d519483a2c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2015-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.
@@ -54,7 +54,7 @@ size_t SharedPromise<T>::size() {
 }
 
 template <class T>
-Future<T> SharedPromise<T>::getFuture() {
+SemiFuture<T> SharedPromise<T>::getSemiFuture() {
   std::lock_guard<std::mutex> g(mutex_);
   size_++;
   if (hasValue_) {
@@ -64,10 +64,15 @@ Future<T> SharedPromise<T>::getFuture() {
     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
@@ -117,7 +122,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
   {
     std::lock_guard<std::mutex> g(mutex_);
     if (hasValue_) {
-      throw PromiseAlreadySatisfied();
+      throwPromiseAlreadySatisfied();
     }
     hasValue_ = true;
     try_ = std::move(t);
@@ -131,7 +136,8 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
 
 template <class T>
 bool SharedPromise<T>::isFulfilled() {
+  std::lock_guard<std::mutex> g(mutex_);
   return hasValue_;
 }
 
-}
+} // namespace folly