class BrokenPromise : public FutureException {
public:
- explicit BrokenPromise() :
- FutureException("Broken promise") { }
+ explicit BrokenPromise(std::string type) :
+ FutureException(
+ (std::string("Broken promise for type name `") + type) + '`') { }
};
class NoState : public FutureException {
// detachPromise() and setResult() should never be called in parallel
// so we don't need to protect this.
if (UNLIKELY(!result_)) {
- setResult(Try<T>(exception_wrapper(BrokenPromise())));
+ setResult(Try<T>(exception_wrapper(BrokenPromise(typeid(T).name()))));
}
detachOne();
}
p.setValue(42); // after here
EXPECT_TRUE(p.isFulfilled());
}
+
+TEST(Promise, brokenOnDelete) {
+ auto p = folly::make_unique<Promise<int>>();
+ auto f = p->getFuture();
+
+ EXPECT_FALSE(f.isReady());
+
+ p.reset();
+
+ EXPECT_TRUE(f.isReady());
+
+ auto t = f.getTry();
+
+ EXPECT_TRUE(t.hasException<BrokenPromise>());
+}
+
+TEST(Promise, brokenPromiseHasTypeInfo) {
+ auto pInt = folly::make_unique<Promise<int>>();
+ auto fInt = pInt->getFuture();
+
+ auto pFloat = folly::make_unique<Promise<float>>();
+ auto fFloat = pFloat->getFuture();
+
+ pInt.reset();
+ pFloat.reset();
+
+ auto whatInt = fInt.getTry().exception().what();
+ auto whatFloat = fFloat.getTry().exception().what();
+
+ EXPECT_NE(whatInt, whatFloat);
+}