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) {
}
template <class T>
Try<T> Future<T>::getTryVia(DrivableExecutor* e) && {
return std::move(waitVia(e).result());
Try<T>& Future<T>::getTryVia(DrivableExecutor* e) {
return waitVia(e).result();
}
template <class T>
Try<T> Future<T>::getTryVia(TimedDrivableExecutor* e, HighResDuration dur) && {
Try<T>& Future<T>::getTryVia(TimedDrivableExecutor* e, HighResDuration dur) {
waitVia(e, dur);
if (!this->isReady()) {
throw_exception<FutureTimeout>();
}
return std::move(result());
return result();
}
namespace futures {
......
......@@ -1143,11 +1143,11 @@ class Future : private futures::detail::FutureBase<T> {
/// Call e->drive() repeatedly until the future is fulfilled. Examples
/// of DrivableExecutor include EventBase and ManualExecutor. Returns a
/// 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
/// 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
/// Future<T> instance.
......
......@@ -465,7 +465,7 @@ TEST(Via, getTryVia) {
ManualExecutor x;
auto f = via(&x).thenValue([](auto&&) { return 23; });
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) {
ManualExecutor x;
auto f = via(&x).then();
EXPECT_FALSE(f.isReady());
auto t = std::move(f).getTryVia(&x);
auto t = f.getTryVia(&x);
EXPECT_TRUE(t.hasValue());
}
{
DummyDrivableExecutor x;
auto f = makeFuture(23);
EXPECT_EQ(23, std::move(f).getTryVia(&x).value());
EXPECT_EQ(23, f.getTryVia(&x).value());
EXPECT_FALSE(x.ran);
}
}
......@@ -489,8 +489,7 @@ TEST(Via, SimpleTimedGetTryVia) {
TimedDrivableExecutor e2;
Promise<folly::Unit> p;
auto f = p.getFuture();
EXPECT_THROW(
std::move(f).getTryVia(&e2, std::chrono::seconds(1)), FutureTimeout);
EXPECT_THROW(f.getTryVia(&e2, std::chrono::seconds(1)), FutureTimeout);
}
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