Commit 3153b1b0 authored by Lee Howes's avatar Lee Howes Committed by Facebook GitHub Bot

r-value qualify Future::getVia for consistency with other get operations

Summary: getVia is destructive like other forms of get. This change r-value qualifies it to highlight that in code.

Reviewed By: yfeldblum

Differential Revision: D23603722

fbshipit-source-id: d2aecac3c6eb09e0fcf55a07e310114ebc13b932
parent 3a2cecf1
...@@ -2379,12 +2379,12 @@ Try<T> Future<T>::getTry(HighResDuration dur) && { ...@@ -2379,12 +2379,12 @@ Try<T> Future<T>::getTry(HighResDuration dur) && {
} }
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());
} }
template <class T> template <class T>
T Future<T>::getVia(TimedDrivableExecutor* e, HighResDuration dur) { T Future<T>::getVia(TimedDrivableExecutor* e, HighResDuration dur) && {
waitVia(e, dur); waitVia(e, dur);
if (!this->isReady()) { if (!this->isReady()) {
throw_exception<FutureTimeout>(); throw_exception<FutureTimeout>();
......
...@@ -1131,14 +1131,14 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1131,14 +1131,14 @@ class Future : private futures::detail::FutureBase<T> {
/// Examples of DrivableExecutor include EventBase and ManualExecutor. /// Examples of DrivableExecutor include EventBase and ManualExecutor.
/// ///
/// Returns the fulfilled value (moved-out) or throws the fulfilled exception. /// Returns the fulfilled value (moved-out) or throws the fulfilled exception.
T getVia(DrivableExecutor* e); T getVia(DrivableExecutor* e) &&;
/// Call e->drive() repeatedly until the future is fulfilled, or `dur` /// Call e->drive() repeatedly until the future is fulfilled, or `dur`
/// elapses. /// elapses.
/// ///
/// Returns the fulfilled value (moved-out), throws the fulfilled exception, /// Returns the fulfilled value (moved-out), throws the fulfilled exception,
/// or on timeout throws FutureTimeout. /// or on timeout throws FutureTimeout.
T getVia(TimedDrivableExecutor* e, HighResDuration dur); T getVia(TimedDrivableExecutor* e, HighResDuration dur) &&;
/// 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
......
...@@ -617,7 +617,7 @@ TEST(SemiFuture, DeferWithVia) { ...@@ -617,7 +617,7 @@ TEST(SemiFuture, DeferWithVia) {
// Run "F" here inline in the calling thread // Run "F" here inline in the calling thread
auto tf = std::move(sf).via(&e2); auto tf = std::move(sf).via(&e2);
p.setValue(); p.setValue();
tf.getVia(&e2); std::move(tf).getVia(&e2);
ASSERT_EQ(innerResult, 17); ASSERT_EQ(innerResult, 17);
} }
...@@ -630,7 +630,7 @@ TEST(SemiFuture, ChainingDefertoThen) { ...@@ -630,7 +630,7 @@ TEST(SemiFuture, ChainingDefertoThen) {
// Run "F" here inline in a task running on the eventbase // Run "F" here inline in a task running on the eventbase
auto tf = std::move(sf).via(&e2).thenValue([&](auto&&) { result = 42; }); auto tf = std::move(sf).via(&e2).thenValue([&](auto&&) { result = 42; });
p.setValue(); p.setValue();
tf.getVia(&e2); std::move(tf).getVia(&e2);
ASSERT_EQ(innerResult, 17); ASSERT_EQ(innerResult, 17);
ASSERT_EQ(result, 42); ASSERT_EQ(result, 42);
} }
...@@ -671,7 +671,7 @@ TEST(SemiFuture, ChainingDefertoThenWithValue) { ...@@ -671,7 +671,7 @@ TEST(SemiFuture, ChainingDefertoThenWithValue) {
// Run "F" here inline in a task running on the eventbase // Run "F" here inline in a task running on the eventbase
auto tf = std::move(sf).via(&e2).thenValue([&](int a) { result = a; }); auto tf = std::move(sf).via(&e2).thenValue([&](int a) { result = a; });
p.setValue(7); p.setValue(7);
tf.getVia(&e2); std::move(tf).getVia(&e2);
ASSERT_EQ(innerResult, 7); ASSERT_EQ(innerResult, 7);
ASSERT_EQ(result, 7); ASSERT_EQ(result, 7);
} }
...@@ -714,7 +714,7 @@ TEST(SemiFuture, DeferWithinContinuation) { ...@@ -714,7 +714,7 @@ TEST(SemiFuture, DeferWithinContinuation) {
}); });
}); });
p.setValue(7); p.setValue(7);
auto r = resultF.getVia(&e2); auto r = std::move(resultF).getVia(&e2);
ASSERT_EQ(r, 7); ASSERT_EQ(r, 7);
ASSERT_EQ(innerResult, 7); ASSERT_EQ(innerResult, 7);
ASSERT_EQ(result, 7); ASSERT_EQ(result, 7);
......
...@@ -126,7 +126,7 @@ TEST_F(ViaFixture, threadHops) { ...@@ -126,7 +126,7 @@ TEST_F(ViaFixture, threadHops) {
EXPECT_EQ(std::this_thread::get_id(), westThreadId); EXPECT_EQ(std::this_thread::get_id(), westThreadId);
return t.value(); return t.value();
}); });
EXPECT_EQ(f.getVia(waiter.get()), 1); EXPECT_EQ(std::move(f).getVia(waiter.get()), 1);
} }
TEST_F(ViaFixture, chainVias) { TEST_F(ViaFixture, chainVias) {
...@@ -158,7 +158,7 @@ TEST_F(ViaFixture, chainVias) { ...@@ -158,7 +158,7 @@ TEST_F(ViaFixture, chainVias) {
return val + 1; return val + 1;
}); });
EXPECT_EQ(f.getVia(waiter.get()), 4); EXPECT_EQ(std::move(f).getVia(waiter.get()), 4);
} }
TEST_F(ViaFixture, bareViaAssignment) { TEST_F(ViaFixture, bareViaAssignment) {
...@@ -434,20 +434,20 @@ TEST(Via, getVia) { ...@@ -434,20 +434,20 @@ TEST(Via, getVia) {
// non-void // non-void
ManualExecutor x; ManualExecutor x;
auto f = via(&x).thenValue([](auto&&) { return true; }); auto f = via(&x).thenValue([](auto&&) { return true; });
EXPECT_TRUE(f.getVia(&x)); EXPECT_TRUE(std::move(f).getVia(&x));
} }
{ {
// void // void
ManualExecutor x; ManualExecutor x;
auto f = via(&x).then(); auto f = via(&x).then();
f.getVia(&x); std::move(f).getVia(&x);
} }
{ {
DummyDrivableExecutor x; DummyDrivableExecutor x;
auto f = makeFuture(true); auto f = makeFuture(true);
EXPECT_TRUE(f.getVia(&x)); EXPECT_TRUE(std::move(f).getVia(&x));
EXPECT_FALSE(x.ran); EXPECT_FALSE(x.ran);
} }
} }
...@@ -456,7 +456,8 @@ TEST(Via, SimpleTimedGetVia) { ...@@ -456,7 +456,8 @@ TEST(Via, SimpleTimedGetVia) {
TimedDrivableExecutor e2; TimedDrivableExecutor e2;
Promise<folly::Unit> p; Promise<folly::Unit> p;
auto f = p.getFuture(); auto f = p.getFuture();
EXPECT_THROW(f.getVia(&e2, std::chrono::seconds(1)), FutureTimeout); EXPECT_THROW(
std::move(f).getVia(&e2, std::chrono::seconds(1)), FutureTimeout);
} }
TEST(Via, getTryVia) { TEST(Via, getTryVia) {
......
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