Commit c9993790 authored by Sim Sun's avatar Sim Sun Committed by Facebook GitHub Bot

Revert D23489967: Modify Future::getTryVia to be r-value qualified and destructive

Differential Revision:
D23489967 (https://github.com/facebook/folly/commit/65bb1505d3f64d9248bc1f7a04abc212db518676)

Original commit changeset: db11c9c5946e

fbshipit-source-id: 4970fc7de479a51d4acf91b2871ff0c15712130e
parent 7187a3af
...@@ -2393,17 +2393,17 @@ T Future<T>::getVia(TimedDrivableExecutor* e, HighResDuration dur) { ...@@ -2393,17 +2393,17 @@ 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 std::move(waitVia(e).result()); return waitVia(e).result();
} }
template <class T> template <class T>
Try<T> Future<T>::getTryVia(TimedDrivableExecutor* e, HighResDuration dur) && { Try<T>& Future<T>::getTryVia(TimedDrivableExecutor* e, HighResDuration dur) {
waitVia(e, dur); waitVia(e, dur);
if (!this->isReady()) { if (!this->isReady()) {
throw_exception<FutureTimeout>(); throw_exception<FutureTimeout>();
} }
return std::move(result()); return result();
} }
namespace futures { namespace futures {
......
...@@ -1143,11 +1143,11 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1143,11 +1143,11 @@ class Future : private futures::detail::FutureBase<T> {
/// Call e->drive() repeatedly until the future is fulfilled. Examples /// Call e->drive() repeatedly until the future is fulfilled. Examples
/// of DrivableExecutor include EventBase and ManualExecutor. Returns a /// of DrivableExecutor include EventBase and ManualExecutor. Returns a
/// reference to the Try of the value. /// reference to the Try of the value.
Try<T> getTryVia(DrivableExecutor* e) &&; Try<T>& getTryVia(DrivableExecutor* e);
/// getTryVia but will wait only until `dur` elapses. Returns the /// getTryVia but will wait only until `dur` elapses. Returns the
/// Try of the value (moved-out) or may throw a FutureTimeout exception. /// Try of the value (moved-out) or may throw a FutureTimeout exception.
Try<T> getTryVia(TimedDrivableExecutor* e, HighResDuration dur) &&; Try<T>& getTryVia(TimedDrivableExecutor* e, HighResDuration dur);
/// Unwraps the case of a Future<Future<T>> instance, and returns a simple /// Unwraps the case of a Future<Future<T>> instance, and returns a simple
/// Future<T> instance. /// Future<T> instance.
......
...@@ -465,7 +465,7 @@ TEST(Via, getTryVia) { ...@@ -465,7 +465,7 @@ TEST(Via, getTryVia) {
ManualExecutor x; ManualExecutor x;
auto f = via(&x).thenValue([](auto&&) { return 23; }); auto f = via(&x).thenValue([](auto&&) { return 23; });
EXPECT_FALSE(f.isReady()); EXPECT_FALSE(f.isReady());
EXPECT_EQ(23, std::move(f).getTryVia(&x).value()); EXPECT_EQ(23, f.getTryVia(&x).value());
} }
{ {
...@@ -473,14 +473,14 @@ TEST(Via, getTryVia) { ...@@ -473,14 +473,14 @@ TEST(Via, getTryVia) {
ManualExecutor x; ManualExecutor x;
auto f = via(&x).then(); auto f = via(&x).then();
EXPECT_FALSE(f.isReady()); EXPECT_FALSE(f.isReady());
auto t = std::move(f).getTryVia(&x); auto t = f.getTryVia(&x);
EXPECT_TRUE(t.hasValue()); EXPECT_TRUE(t.hasValue());
} }
{ {
DummyDrivableExecutor x; DummyDrivableExecutor x;
auto f = makeFuture(23); auto f = makeFuture(23);
EXPECT_EQ(23, std::move(f).getTryVia(&x).value()); EXPECT_EQ(23, f.getTryVia(&x).value());
EXPECT_FALSE(x.ran); EXPECT_FALSE(x.ran);
} }
} }
...@@ -489,8 +489,7 @@ TEST(Via, SimpleTimedGetTryVia) { ...@@ -489,8 +489,7 @@ TEST(Via, SimpleTimedGetTryVia) {
TimedDrivableExecutor e2; TimedDrivableExecutor e2;
Promise<folly::Unit> p; Promise<folly::Unit> p;
auto f = p.getFuture(); auto f = p.getFuture();
EXPECT_THROW( EXPECT_THROW(f.getTryVia(&e2, std::chrono::seconds(1)), FutureTimeout);
std::move(f).getTryVia(&e2, std::chrono::seconds(1)), FutureTimeout);
} }
TEST(Via, waitVia) { TEST(Via, waitVia) {
......
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