Commit 5d517eb7 authored by Lee Howes's avatar Lee Howes Committed by Facebook GitHub Bot

Remove Future::getTry

Summary:
getTry reads like a blocking operation but is actually non-blocking.

Remove to avoid confusion.

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D22494732

fbshipit-source-id: d884d60cc14e2a53cd0657926a885a12b994c1ee
parent 2e45ff8d
...@@ -2293,7 +2293,7 @@ Try<T> SemiFuture<T>::getTry() && { ...@@ -2293,7 +2293,7 @@ Try<T> SemiFuture<T>::getTry() && {
wait(); wait();
auto future = folly::Future<T>(this->core_); auto future = folly::Future<T>(this->core_);
this->core_ = nullptr; this->core_ = nullptr;
return std::move(std::move(future).getTry()); return std::move(std::move(future).result());
} }
template <class T> template <class T>
...@@ -2305,7 +2305,7 @@ Try<T> SemiFuture<T>::getTry(HighResDuration dur) && { ...@@ -2305,7 +2305,7 @@ Try<T> SemiFuture<T>::getTry(HighResDuration dur) && {
if (!future.isReady()) { if (!future.isReady()) {
throw_exception<FutureTimeout>(); throw_exception<FutureTimeout>();
} }
return std::move(std::move(future).getTry()); return std::move(std::move(future).result());
} }
template <class T> template <class T>
...@@ -2374,11 +2374,6 @@ T Future<T>::get(HighResDuration dur) && { ...@@ -2374,11 +2374,6 @@ T Future<T>::get(HighResDuration dur) && {
return std::move(future).value(); return std::move(future).value();
} }
template <class T>
Try<T>& Future<T>::getTry() {
return result();
}
template <class T> template <class T>
T Future<T>::getVia(DrivableExecutor* e) { T Future<T>::getVia(DrivableExecutor* e) {
return std::move(waitVia(e).value()); return std::move(waitVia(e).value());
...@@ -2395,7 +2390,7 @@ T Future<T>::getVia(TimedDrivableExecutor* e, HighResDuration dur) { ...@@ -2395,7 +2390,7 @@ T Future<T>::getVia(TimedDrivableExecutor* e, HighResDuration dur) {
template <class T> template <class T>
Try<T>& Future<T>::getTryVia(DrivableExecutor* e) { Try<T>& Future<T>::getTryVia(DrivableExecutor* e) {
return waitVia(e).getTry(); return waitVia(e).result();
} }
template <class T> template <class T>
......
...@@ -1732,14 +1732,6 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1732,14 +1732,6 @@ class Future : private futures::detail::FutureBase<T> {
/// - `valid() == false` /// - `valid() == false`
T get(HighResDuration dur) &&; T get(HighResDuration dur) &&;
/// A reference to the Try of the value
///
/// Preconditions:
///
/// - `valid() == true` (else throws FutureInvalid)
/// - `isReady() == true` (else throws FutureNotReady)
Try<T>& getTry();
/// Blocks until this Future is complete. /// Blocks until this Future is complete.
/// ///
/// Preconditions: /// Preconditions:
...@@ -2615,7 +2607,7 @@ class FutureAwaitable { ...@@ -2615,7 +2607,7 @@ class FutureAwaitable {
bool await_ready() { bool await_ready() {
if (future_.isReady()) { if (future_.isReady()) {
result_ = std::move(future_.getTry()); result_ = std::move(future_.result());
return true; return true;
} }
return false; return false;
......
...@@ -221,7 +221,6 @@ TEST(Future, hasPreconditionValid) { ...@@ -221,7 +221,6 @@ TEST(Future, hasPreconditionValid) {
DOIT(f.result()); DOIT(f.result());
DOIT(std::move(f).get()); DOIT(std::move(f).get());
DOIT(std::move(f).get(std::chrono::milliseconds(10))); DOIT(std::move(f).get(std::chrono::milliseconds(10)));
DOIT(f.getTry());
DOIT(f.hasValue()); DOIT(f.hasValue());
DOIT(f.hasException()); DOIT(f.hasException());
DOIT(f.value()); DOIT(f.value());
...@@ -249,11 +248,9 @@ TEST(Future, hasPostconditionValid) { ...@@ -249,11 +248,9 @@ TEST(Future, hasPostconditionValid) {
DOIT(swallow(f.hasValue())); DOIT(swallow(f.hasValue()));
DOIT(swallow(f.hasException())); DOIT(swallow(f.hasException()));
DOIT(swallow(f.value())); DOIT(swallow(f.value()));
DOIT(swallow(f.getTry()));
DOIT(swallow(f.poll())); DOIT(swallow(f.poll()));
DOIT(f.raise(std::logic_error("foo"))); DOIT(f.raise(std::logic_error("foo")));
DOIT(f.cancel()); DOIT(f.cancel());
DOIT(swallow(f.getTry()));
DOIT(f.wait()); DOIT(f.wait());
DOIT(std::move(f.wait())); DOIT(std::move(f.wait()));
...@@ -915,13 +912,13 @@ TEST(Future, futureNotReady) { ...@@ -915,13 +912,13 @@ TEST(Future, futureNotReady) {
} }
TEST(Future, hasException) { TEST(Future, hasException) {
EXPECT_TRUE(makeFuture<int>(eggs).getTry().hasException()); EXPECT_TRUE(makeFuture<int>(eggs).result().hasException());
EXPECT_FALSE(makeFuture(42).getTry().hasException()); EXPECT_FALSE(makeFuture(42).result().hasException());
} }
TEST(Future, hasValue) { TEST(Future, hasValue) {
EXPECT_TRUE(makeFuture(42).getTry().hasValue()); EXPECT_TRUE(makeFuture(42).result().hasValue());
EXPECT_FALSE(makeFuture<int>(eggs).getTry().hasValue()); EXPECT_FALSE(makeFuture<int>(eggs).result().hasValue());
} }
TEST(Future, makeFuture) { TEST(Future, makeFuture) {
...@@ -1418,7 +1415,7 @@ TEST(Future, NoThrow) { ...@@ -1418,7 +1415,7 @@ TEST(Future, NoThrow) {
ADD_FAILURE() << "This code should be unreachable"; ADD_FAILURE() << "This code should be unreachable";
return std::move(value); return std::move(value);
}) })
.getTry(); .result();
EXPECT_TRUE(t.hasException()); EXPECT_TRUE(t.hasException());
EXPECT_EQ(t.exception().get_exception()->what(), kErrorMessage); EXPECT_EQ(t.exception().get_exception()->what(), kErrorMessage);
...@@ -1433,7 +1430,7 @@ TEST(Future, NoThrow) { ...@@ -1433,7 +1430,7 @@ TEST(Future, NoThrow) {
return std::move(value); return std::move(value);
}) })
.via(&InlineExecutor::instance()) .via(&InlineExecutor::instance())
.getTry(); .result();
EXPECT_TRUE(t.hasException()); EXPECT_TRUE(t.hasException());
EXPECT_EQ(t.exception().get_exception()->what(), kErrorMessage); EXPECT_EQ(t.exception().get_exception()->what(), kErrorMessage);
......
...@@ -365,7 +365,7 @@ TEST(Promise, brokenOnDelete) { ...@@ -365,7 +365,7 @@ TEST(Promise, brokenOnDelete) {
EXPECT_TRUE(f.isReady()); EXPECT_TRUE(f.isReady());
auto t = f.getTry(); auto t = f.result();
EXPECT_TRUE(t.hasException<BrokenPromise>()); EXPECT_TRUE(t.hasException<BrokenPromise>());
} }
...@@ -380,8 +380,8 @@ TEST(Promise, brokenPromiseHasTypeInfo) { ...@@ -380,8 +380,8 @@ TEST(Promise, brokenPromiseHasTypeInfo) {
pInt.reset(); pInt.reset();
pFloat.reset(); pFloat.reset();
auto whatInt = fInt.getTry().exception().what(); auto whatInt = fInt.result().exception().what();
auto whatFloat = fFloat.getTry().exception().what(); auto whatFloat = fFloat.result().exception().what();
EXPECT_NE(whatInt, whatFloat); EXPECT_NE(whatInt, whatFloat);
} }
...@@ -97,7 +97,7 @@ TEST(RetryingTest, future_factory_throws) { ...@@ -97,7 +97,7 @@ TEST(RetryingTest, future_factory_throws) {
} }
}) })
.wait() .wait()
.getTry(); .result();
EXPECT_THROW(result.throwIfFailed(), ThrownException); EXPECT_THROW(result.throwIfFailed(), ThrownException);
} }
......
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