Commit fc0470a9 authored by Elliott Clark's avatar Elliott Clark Committed by facebook-github-bot-4

Add SharedPromise<T>::isFulfilled

Summary: Promise<T> has isFulFilled. This patch adds the corresponding functionality to shared promise.

Reviewed By: @jsedgwick

Differential Revision: D2417631
parent 9f9e6d96
...@@ -124,4 +124,9 @@ void SharedPromise<T>::setTry(Try<T>&& t) { ...@@ -124,4 +124,9 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
} }
} }
template <class T>
bool SharedPromise<T>::isFulfilled() {
return hasValue_;
}
} }
...@@ -105,6 +105,8 @@ public: ...@@ -105,6 +105,8 @@ public:
template <class F> template <class F>
void setWith(F&& func); void setWith(F&& func);
bool isFulfilled();
private: private:
std::mutex mutex_; std::mutex mutex_;
size_t size_{0}; size_t size_{0};
......
...@@ -106,3 +106,14 @@ TEST(SharedPromise, setWith) { ...@@ -106,3 +106,14 @@ TEST(SharedPromise, setWith) {
p.setWith([]{ return 1; }); p.setWith([]{ return 1; });
EXPECT_EQ(1, p.getFuture().value()); 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());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment