Commit 323c9a33 authored by Hans Fugal's avatar Hans Fugal Committed by Pavlo Kushnir

Promise::isFulfilled()

Summary: See task

Test Plan: runtests

Reviewed By: jsedgwick@fb.com

Subscribers: exa, folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D2101549

Tasks: 7225286

Signature: t1:2101549:1432688294:5fb9d7370c38c1392429a09ba48b131cac16647d
parent 5575da1f
......@@ -130,4 +130,12 @@ void Promise<T>::setWith(F&& func) {
setTry(makeTryWith(std::forward<F>(func)));
}
template <class T>
bool Promise<T>::isFulfilled() {
if (core_) {
return core_->hasResult();
}
return true;
}
}
......@@ -99,6 +99,8 @@ public:
template <class F>
void setWith(F&& func);
bool isFulfilled();
private:
typedef typename Future<T>::corePtr corePtr;
......
......@@ -1914,3 +1914,20 @@ TEST(Map, Basic) {
EXPECT_TRUE(collect(fs2).isReady());
}
TEST(Promise, isFulfilled) {
Promise<int> p;
EXPECT_FALSE(p.isFulfilled());
p.setValue(42);
EXPECT_TRUE(p.isFulfilled());
}
TEST(Promise, isFulfilledWithFuture) {
Promise<int> p;
auto f = p.getFuture(); // so core_ will become null
EXPECT_FALSE(p.isFulfilled());
p.setValue(42); // after here
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