From fc0470a93d86dec8fe9fa3db7bc05672cc8979b0 Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Thu, 10 Sep 2015 00:31:47 -0700 Subject: [PATCH] Add SharedPromise::isFulfilled Summary: Promise has isFulFilled. This patch adds the corresponding functionality to shared promise. Reviewed By: @jsedgwick Differential Revision: D2417631 --- folly/futures/SharedPromise-inl.h | 5 +++++ folly/futures/SharedPromise.h | 2 ++ folly/futures/test/SharedPromiseTest.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/folly/futures/SharedPromise-inl.h b/folly/futures/SharedPromise-inl.h index c2f6d454..76bd0cae 100644 --- a/folly/futures/SharedPromise-inl.h +++ b/folly/futures/SharedPromise-inl.h @@ -124,4 +124,9 @@ void SharedPromise::setTry(Try&& t) { } } +template +bool SharedPromise::isFulfilled() { + return hasValue_; +} + } diff --git a/folly/futures/SharedPromise.h b/folly/futures/SharedPromise.h index dc37e004..11419302 100644 --- a/folly/futures/SharedPromise.h +++ b/folly/futures/SharedPromise.h @@ -105,6 +105,8 @@ public: template void setWith(F&& func); + bool isFulfilled(); + private: std::mutex mutex_; size_t size_{0}; diff --git a/folly/futures/test/SharedPromiseTest.cpp b/folly/futures/test/SharedPromiseTest.cpp index 77095b15..1dd23b85 100644 --- a/folly/futures/test/SharedPromiseTest.cpp +++ b/folly/futures/test/SharedPromiseTest.cpp @@ -106,3 +106,14 @@ TEST(SharedPromise, setWith) { p.setWith([]{ return 1; }); EXPECT_EQ(1, p.getFuture().value()); } + +TEST(SharedPromise, isFulfilled) { + SharedPromise 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()); +} -- 2.34.1