Commit 56df65be authored by Hans Fugal's avatar Hans Fugal Committed by Chip Turner

(wangle) set* should not invalidate getFuture

Summary: @jcoens observed in D1451114 that it was unintuitive that you have to retrieve the `Future` before fulfilling the `Promise`. That seemed wrong to me too, but sure enough when I wrote the unit tests that doesn't work (throws "promise already fulfilled" when you call `getFuture`). I think this is just a simple mistake, but I'm going to carefully look at the output of contbuild test suites before committing.

Test Plan:
red-green
careful dependency unit test inspection

Reviewed By: jon.coens@fb.com

Subscribers: net-systems@, fugalh, exa, jcoens

FB internal diff: D1453780
parent a99854ba
......@@ -72,7 +72,6 @@ void Promise<T>::detach() {
template <class T>
Future<T> Promise<T>::getFuture() {
throwIfRetrieved();
throwIfFulfilled();
retrieved_ = true;
return Future<T>(state_);
}
......
......@@ -788,3 +788,15 @@ TEST(Future, viaIsCold) {
EXPECT_EQ(1, x.run());
EXPECT_EQ(1, count);
}
TEST(Future, getFuture_after_setValue) {
Promise<int> p;
p.setValue(42);
EXPECT_EQ(42, p.getFuture().value());
}
TEST(Future, getFuture_after_setException) {
Promise<void> p;
p.fulfil([]() -> void { throw std::logic_error("foo"); });
EXPECT_THROW(p.getFuture().value(), std::logic_error);
}
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