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
template <class T>
Future<T> Promise<T>::getFuture() {
throwIfRetrieved();
- throwIfFulfilled();
retrieved_ = true;
return Future<T>(state_);
}
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);
+}