Add SharedPromise<T>::isFulfilled
authorElliott Clark <elliott@fb.com>
Thu, 10 Sep 2015 07:31:47 +0000 (00:31 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Thu, 10 Sep 2015 08:20:17 +0000 (01:20 -0700)
Summary: Promise<T> has isFulFilled. This patch adds the corresponding functionality to shared promise.

Reviewed By: @jsedgwick

Differential Revision: D2417631

folly/futures/SharedPromise-inl.h
folly/futures/SharedPromise.h
folly/futures/test/SharedPromiseTest.cpp

index c2f6d45428d35e4966e272c0e25ec839486373d4..76bd0caec266b316f5e6af90e8882a0a55909606 100644 (file)
@@ -124,4 +124,9 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
   }
 }
 
+template <class T>
+bool SharedPromise<T>::isFulfilled() {
+  return hasValue_;
+}
+
 }
index dc37e004854110344bb7105c0ed18a88b2992b80..114193029cf4fe5ff15475e0227dbadccc3d2c36 100644 (file)
@@ -105,6 +105,8 @@ public:
   template <class F>
   void setWith(F&& func);
 
+  bool isFulfilled();
+
 private:
   std::mutex mutex_;
   size_t size_{0};
index 77095b1559f8a221e5b5f275b647bd0f7e4795a7..1dd23b85bc46c5a9ee6b010fa55940c379e771b3 100644 (file)
@@ -106,3 +106,14 @@ TEST(SharedPromise, setWith) {
   p.setWith([]{ return 1; });
   EXPECT_EQ(1, p.getFuture().value());
 }
+
+TEST(SharedPromise, isFulfilled) {
+  SharedPromise<int> p;
+  EXPECT_FALSE(p.isFulfilled());
+  auto p2 = std::move(p);
+  EXPECT_FALSE(p2.isFulfilled());
+  p2.setValue(1);
+  EXPECT_TRUE(p2.isFulfilled());
+  p = std::move(p2);
+  EXPECT_TRUE(p.isFulfilled());
+}