Commit d3d1f745 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Remove nullary then from tests.

Summary:
Remove falls to Future::then that take a nullary lambda. This is deprecated and will be deleted.

This change replaces them with thenValue([](auto&&){...}) or similar.

This does not replace all calls to then with thenValue - other forms will be replaced when those forms of then are due for deletion.

Reviewed By: yfeldblum

Differential Revision: D10219070

fbshipit-source-id: 13b6f64ee2d7c8741537fe1131bdf3b251361413
parent 86a13ee9
...@@ -60,7 +60,7 @@ class CallbackLifetimeTest : public testing::Test { ...@@ -60,7 +60,7 @@ class CallbackLifetimeTest : public testing::Test {
}); });
} }
static void raise() { static void raise(folly::Unit = folly::Unit{}) {
if (kRaiseWillThrow()) { // to avoid marking [[noreturn]] if (kRaiseWillThrow()) { // to avoid marking [[noreturn]]
throw std::runtime_error("raise"); throw std::runtime_error("raise");
} }
...@@ -76,32 +76,36 @@ class CallbackLifetimeTest : public testing::Test { ...@@ -76,32 +76,36 @@ class CallbackLifetimeTest : public testing::Test {
TEST_F(CallbackLifetimeTest, thenReturnsValue) { TEST_F(CallbackLifetimeTest, thenReturnsValue) {
auto c = mkC(); auto c = mkC();
via(&executor).then([_ = mkCGuard(c)] {}).wait(); via(&executor).thenValue([_ = mkCGuard(c)](auto&&) {}).wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
} }
TEST_F(CallbackLifetimeTest, thenReturnsValueThrows) { TEST_F(CallbackLifetimeTest, thenReturnsValueThrows) {
auto c = mkC(); auto c = mkC();
via(&executor).then([_ = mkCGuard(c)] { raise(); }).wait(); via(&executor).thenValue([_ = mkCGuard(c)](auto&&) { raise(); }).wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
} }
TEST_F(CallbackLifetimeTest, thenReturnsFuture) { TEST_F(CallbackLifetimeTest, thenReturnsFuture) {
auto c = mkC(); auto c = mkC();
via(&executor).then([_ = mkCGuard(c)] { return makeFuture(); }).wait(); via(&executor)
.thenValue([_ = mkCGuard(c)](auto&&) { return makeFuture(); })
.wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
} }
TEST_F(CallbackLifetimeTest, thenReturnsFutureThrows) { TEST_F(CallbackLifetimeTest, thenReturnsFutureThrows) {
auto c = mkC(); auto c = mkC();
via(&executor).then([_ = mkCGuard(c)] { return raiseFut(); }).wait(); via(&executor)
.thenValue([_ = mkCGuard(c)](auto&&) { return raiseFut(); })
.wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
} }
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatch) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatch) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::exception&) {}) .onError([_ = mkCGuard(c)](std::exception&) {})
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -110,7 +114,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatch) { ...@@ -110,7 +114,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatch) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatchThrows) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatchThrows) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::exception&) { raise(); }) .onError([_ = mkCGuard(c)](std::exception&) { raise(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -119,7 +123,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatchThrows) { ...@@ -119,7 +123,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueMatchThrows) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrong) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrong) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::logic_error&) {}) .onError([_ = mkCGuard(c)](std::logic_error&) {})
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -128,7 +132,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrong) { ...@@ -128,7 +132,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrong) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrongThrows) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrongThrows) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::logic_error&) { raise(); }) .onError([_ = mkCGuard(c)](std::logic_error&) { raise(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -137,7 +141,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrongThrows) { ...@@ -137,7 +141,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsValueWrongThrows) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatch) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatch) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::exception&) { return makeFuture(); }) .onError([_ = mkCGuard(c)](std::exception&) { return makeFuture(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -146,7 +150,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatch) { ...@@ -146,7 +150,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatch) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatchThrows) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatchThrows) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::exception&) { return raiseFut(); }) .onError([_ = mkCGuard(c)](std::exception&) { return raiseFut(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -155,7 +159,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatchThrows) { ...@@ -155,7 +159,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureMatchThrows) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrong) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrong) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::logic_error&) { return makeFuture(); }) .onError([_ = mkCGuard(c)](std::logic_error&) { return makeFuture(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -164,7 +168,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrong) { ...@@ -164,7 +168,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrong) {
TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrongThrows) { TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrongThrows) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](std::logic_error&) { return raiseFut(); }) .onError([_ = mkCGuard(c)](std::logic_error&) { return raiseFut(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -173,7 +177,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrongThrows) { ...@@ -173,7 +177,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesExnReturnsFutureWrongThrows) {
TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValue) { TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValue) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](exception_wrapper&&) {}) .onError([_ = mkCGuard(c)](exception_wrapper&&) {})
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -182,7 +186,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValue) { ...@@ -182,7 +186,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValue) {
TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValueThrows) { TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValueThrows) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](exception_wrapper&&) { raise(); }) .onError([_ = mkCGuard(c)](exception_wrapper&&) { raise(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -191,7 +195,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValueThrows) { ...@@ -191,7 +195,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsValueThrows) {
TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsFuture) { TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsFuture) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](exception_wrapper&&) { return makeFuture(); }) .onError([_ = mkCGuard(c)](exception_wrapper&&) { return makeFuture(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
...@@ -200,7 +204,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsFuture) { ...@@ -200,7 +204,7 @@ TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsFuture) {
TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsFutureThrows) { TEST_F(CallbackLifetimeTest, onErrorTakesWrapReturnsFutureThrows) {
auto c = mkC(); auto c = mkC();
via(&executor) via(&executor)
.then(raise) .thenValue(raise)
.onError([_ = mkCGuard(c)](exception_wrapper&&) { return raiseFut(); }) .onError([_ = mkCGuard(c)](exception_wrapper&&) { return raiseFut(); })
.wait(); .wait();
EXPECT_EQ(1, *c); EXPECT_EQ(1, *c);
......
...@@ -44,7 +44,7 @@ TEST(Context, basic) { ...@@ -44,7 +44,7 @@ TEST(Context, basic) {
// Start a future // Start a future
Promise<Unit> p; Promise<Unit> p;
auto future = p.getFuture().then([&] { auto future = p.getFuture().thenValue([&](auto&&) {
// Check that the context followed the future // Check that the context followed the future
EXPECT_TRUE(RequestContext::get() != nullptr); EXPECT_TRUE(RequestContext::get() != nullptr);
auto a = auto a =
......
...@@ -39,9 +39,9 @@ TEST(Ensure, mutableLambda) { ...@@ -39,9 +39,9 @@ TEST(Ensure, mutableLambda) {
set->insert(1); set->insert(1);
set->insert(2); set->insert(2);
auto f = makeFuture(4).ensure([set]() mutable { set->clear(); }).then([]() { auto f = makeFuture(4)
throw std::runtime_error("ensure"); .ensure([set]() mutable { set->clear(); })
}); .thenValue([](auto&&) { throw std::runtime_error("ensure"); });
EXPECT_EQ(0, set->size()); EXPECT_EQ(0, set->size());
EXPECT_THROW(std::move(f).get(), std::runtime_error); EXPECT_THROW(std::move(f).get(), std::runtime_error);
......
This diff is collapsed.
...@@ -23,8 +23,10 @@ TEST(NonCopyableLambda, basic) { ...@@ -23,8 +23,10 @@ TEST(NonCopyableLambda, basic) {
Promise<int> promise; Promise<int> promise;
Future<int> future = promise.getFuture(); Future<int> future = promise.getFuture();
Future<Unit>().then(std::bind( Future<Unit>().thenValue(std::bind(
[](Promise<int>& p2) mutable { p2.setValue(123); }, std::move(promise))); [](Promise<int>& p2, folly::Unit) mutable { p2.setValue(123); },
std::move(promise),
std::placeholders::_1));
// The previous statement can be simplified in C++14: // The previous statement can be simplified in C++14:
// Future<Unit>().then([promise = std::move(promise)]() mutable { // Future<Unit>().then([promise = std::move(promise)]() mutable {
...@@ -41,12 +43,13 @@ TEST(NonCopyableLambda, unique_ptr) { ...@@ -41,12 +43,13 @@ TEST(NonCopyableLambda, unique_ptr) {
EXPECT_EQ(*int_ptr, 1); EXPECT_EQ(*int_ptr, 1);
auto future = promise.getFuture().then(std::bind( auto future = promise.getFuture().thenValue(std::bind(
[](std::unique_ptr<int>& p) mutable { [](std::unique_ptr<int>& p, folly::Unit) mutable {
++*p; ++*p;
return std::move(p); return std::move(p);
}, },
std::move(int_ptr))); std::move(int_ptr),
std::placeholders::_1));
// The previous statement can be simplified in C++14: // The previous statement can be simplified in C++14:
// auto future = // auto future =
......
...@@ -106,16 +106,18 @@ TEST(RetryingTest, policy_throws) { ...@@ -106,16 +106,18 @@ TEST(RetryingTest, policy_throws) {
TEST(RetryingTest, policy_future) { TEST(RetryingTest, policy_future) {
atomic<size_t> sleeps{0}; atomic<size_t> sleeps{0};
auto r = futures::retrying( auto r =
[&](size_t n, const exception_wrapper&) { futures::retrying(
return n < 3 ? makeFuture(++sleeps).then([] { return true; }) [&](size_t n, const exception_wrapper&) {
: makeFuture(false); return n < 3
}, ? makeFuture(++sleeps).thenValue([](auto&&) { return true; })
[](size_t n) { : makeFuture(false);
return n < 2 ? makeFuture<size_t>(runtime_error("ha")) },
: makeFuture(n); [](size_t n) {
}) return n < 2 ? makeFuture<size_t>(runtime_error("ha"))
.wait(); : makeFuture(n);
})
.wait();
EXPECT_EQ(2, r.value()); EXPECT_EQ(2, r.value());
EXPECT_EQ(2, sleeps); EXPECT_EQ(2, sleeps);
} }
...@@ -209,7 +211,7 @@ TEST(RetryingTest, large_retries) { ...@@ -209,7 +211,7 @@ TEST(RetryingTest, large_retries) {
// size of implicit promise is at least the size of the return. // size of implicit promise is at least the size of the return.
using LargeReturn = array<uint64_t, 16000>; using LargeReturn = array<uint64_t, 16000>;
auto func = [&executor](size_t retryNum) -> Future<LargeReturn> { auto func = [&executor](size_t retryNum) -> Future<LargeReturn> {
return via(&executor).then([retryNum] { return via(&executor).thenValue([retryNum](auto&&) {
return retryNum < 10000 return retryNum < 10000
? makeFuture<LargeReturn>( ? makeFuture<LargeReturn>(
make_exception_wrapper<std::runtime_error>("keep trying")) make_exception_wrapper<std::runtime_error>("keep trying"))
...@@ -221,7 +223,7 @@ TEST(RetryingTest, large_retries) { ...@@ -221,7 +223,7 @@ TEST(RetryingTest, large_retries) {
for (auto idx = 0; idx < 40; ++idx) { for (auto idx = 0; idx < 40; ++idx) {
futures.emplace_back(futures::retrying( futures.emplace_back(futures::retrying(
[&executor](size_t, const exception_wrapper&) { [&executor](size_t, const exception_wrapper&) {
return via(&executor).then([] { return true; }); return via(&executor).thenValue([](auto&&) { return true; });
}, },
func)); func));
} }
......
...@@ -67,7 +67,7 @@ TEST(SelfDestruct, throwingInlineExecutor) { ...@@ -67,7 +67,7 @@ TEST(SelfDestruct, throwingInlineExecutor) {
auto* p = new Promise<int>(); auto* p = new Promise<int>();
auto future = p->getFuture() auto future = p->getFuture()
.via(&executor) .via(&executor)
.then([p]() -> int { .thenValue([p](auto &&) -> int {
delete p; delete p;
throw ThrowingExecutorError("callback throws"); throw ThrowingExecutorError("callback throws");
}) })
......
...@@ -632,7 +632,7 @@ TEST(SemiFuture, ChainingDefertoThen) { ...@@ -632,7 +632,7 @@ TEST(SemiFuture, ChainingDefertoThen) {
auto f = p.getSemiFuture().toUnsafeFuture(); auto f = p.getSemiFuture().toUnsafeFuture();
auto sf = std::move(f).semi().defer([&](auto&&) { innerResult = 17; }); auto sf = std::move(f).semi().defer([&](auto&&) { innerResult = 17; });
// 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).then([&]() { result = 42; }); auto tf = std::move(sf).via(&e2).thenValue([&](auto&&) { result = 42; });
p.setValue(); p.setValue();
tf.getVia(&e2); tf.getVia(&e2);
ASSERT_EQ(innerResult, 17); ASSERT_EQ(innerResult, 17);
......
...@@ -40,7 +40,6 @@ TEST(Basic, thenVariants) { ...@@ -40,7 +40,6 @@ TEST(Basic, thenVariants) {
{Future<B> f = someFuture<A>().then(aStdFunction<Future<B>, A>());} {Future<B> f = someFuture<A>().then(aStdFunction<Future<B>, A>());}
{Future<B> f = someFuture<A>().then([&](A){return someFuture<B>();});} {Future<B> f = someFuture<A>().then([&](A){return someFuture<B>();});}
{Future<B> f = someFuture<A>().then(&SomeClass::aMethod<Future<B>, A&>, &anObject);} {Future<B> f = someFuture<A>().then(&SomeClass::aMethod<Future<B>, A&>, &anObject);}
{Future<B> f = someFuture<A>().then([&](){return someFuture<B>();});}
{Future<B> f = someFuture<A>().then(&aFunction<B, Try<A>&&>);} {Future<B> f = someFuture<A>().then(&aFunction<B, Try<A>&&>);}
{Future<B> f = someFuture<A>().then(&SomeClass::aStaticMethod<B, Try<A>&&>);} {Future<B> f = someFuture<A>().then(&SomeClass::aStaticMethod<B, Try<A>&&>);}
{Future<B> f = someFuture<A>().then(&SomeClass::aMethod<B, Try<A>&&>, &anObject);} {Future<B> f = someFuture<A>().then(&SomeClass::aMethod<B, Try<A>&&>, &anObject);}
...@@ -73,6 +72,5 @@ TEST(Basic, thenVariants) { ...@@ -73,6 +72,5 @@ TEST(Basic, thenVariants) {
{Future<B> f = someFuture<A>().then(aStdFunction<B, A>());} {Future<B> f = someFuture<A>().then(aStdFunction<B, A>());}
{Future<B> f = someFuture<A>().then([&](A){return B();});} {Future<B> f = someFuture<A>().then([&](A){return B();});}
{Future<B> f = someFuture<A>().then(&SomeClass::aMethod<B, A&>, &anObject);} {Future<B> f = someFuture<A>().then(&SomeClass::aMethod<B, A&>, &anObject);}
{Future<B> f = someFuture<A>().then([&](){return B();});}
// clang-format on // clang-format on
} }
...@@ -179,7 +179,7 @@ TEST(Then, constValue) { ...@@ -179,7 +179,7 @@ TEST(Then, constValue) {
TEST(Then, objectAliveDuringImmediateNoParamContinuation) { TEST(Then, objectAliveDuringImmediateNoParamContinuation) {
auto f = makeFuture<CountedWidget>(23); auto f = makeFuture<CountedWidget>(23);
auto called = false; auto called = false;
std::move(f).then([&] { std::move(f).thenValue([&](auto&&) {
EXPECT_EQ(CountedWidget::instances_.size(), 1u); EXPECT_EQ(CountedWidget::instances_.size(), 1u);
EXPECT_EQ(CountedWidget::instances_[0]->v_, 23); EXPECT_EQ(CountedWidget::instances_[0]->v_, 23);
called = true; called = true;
...@@ -190,7 +190,7 @@ TEST(Then, objectAliveDuringImmediateNoParamContinuation) { ...@@ -190,7 +190,7 @@ TEST(Then, objectAliveDuringImmediateNoParamContinuation) {
TEST(Then, objectAliveDuringDeferredNoParamContinuation) { TEST(Then, objectAliveDuringDeferredNoParamContinuation) {
auto p = Promise<CountedWidget>{}; auto p = Promise<CountedWidget>{};
bool called = false; bool called = false;
p.getFuture().then([&] { p.getFuture().thenValue([&](auto&&) {
EXPECT_EQ(CountedWidget::instances_.size(), 1u); EXPECT_EQ(CountedWidget::instances_.size(), 1u);
EXPECT_EQ(CountedWidget::instances_[0]->v_, 23); EXPECT_EQ(CountedWidget::instances_[0]->v_, 23);
called = true; called = true;
......
...@@ -109,8 +109,10 @@ TEST(Timekeeper, semiFutureWithinHandlesNullTimekeeperSingleton) { ...@@ -109,8 +109,10 @@ TEST(Timekeeper, semiFutureWithinHandlesNullTimekeeperSingleton) {
TEST(Timekeeper, futureDelayed) { TEST(Timekeeper, futureDelayed) {
auto t1 = now(); auto t1 = now();
auto dur = auto dur = makeFuture()
makeFuture().delayed(one_ms).then([=] { return now() - t1; }).get(); .delayed(one_ms)
.thenValue([=](auto&&) { return now() - t1; })
.get();
EXPECT_GE(dur, one_ms); EXPECT_GE(dur, one_ms);
} }
...@@ -120,7 +122,7 @@ TEST(Timekeeper, semiFutureDelayed) { ...@@ -120,7 +122,7 @@ TEST(Timekeeper, semiFutureDelayed) {
auto dur = makeSemiFuture() auto dur = makeSemiFuture()
.delayed(one_ms) .delayed(one_ms)
.toUnsafeFuture() .toUnsafeFuture()
.then([=] { return now() - t1; }) .thenValue([=](auto&&) { return now() - t1; })
.get(); .get();
EXPECT_GE(dur, one_ms); EXPECT_GE(dur, one_ms);
...@@ -128,8 +130,10 @@ TEST(Timekeeper, semiFutureDelayed) { ...@@ -128,8 +130,10 @@ TEST(Timekeeper, semiFutureDelayed) {
TEST(Timekeeper, futureDelayedUnsafe) { TEST(Timekeeper, futureDelayedUnsafe) {
auto t1 = now(); auto t1 = now();
auto dur = auto dur = makeFuture()
makeFuture().delayedUnsafe(one_ms).then([=] { return now() - t1; }).get(); .delayedUnsafe(one_ms)
.thenValue([=](auto&&) { return now() - t1; })
.get();
EXPECT_GE(dur, one_ms); EXPECT_GE(dur, one_ms);
} }
...@@ -149,7 +153,7 @@ TEST(Timekeeper, futureDelayedStickyExecutor) { ...@@ -149,7 +153,7 @@ TEST(Timekeeper, futureDelayedStickyExecutor) {
std::thread::id task_thread_id{}; std::thread::id task_thread_id{};
auto dur = makeFuture() auto dur = makeFuture()
.delayed(one_ms, &tk) .delayed(one_ms, &tk)
.then([=, &task_thread_id] { .thenValue([=, &task_thread_id](auto&&) {
task_thread_id = std::this_thread::get_id(); task_thread_id = std::this_thread::get_id();
return now() - t1; return now() - t1;
}) })
...@@ -176,11 +180,11 @@ TEST(Timekeeper, futureDelayedStickyExecutor) { ...@@ -176,11 +180,11 @@ TEST(Timekeeper, futureDelayedStickyExecutor) {
}}; }};
auto dur = makeSemiFuture() auto dur = makeSemiFuture()
.via(&me) .via(&me)
.then([&first_task_thread_id] { .thenValue([&first_task_thread_id](auto&&) {
first_task_thread_id = std::this_thread::get_id(); first_task_thread_id = std::this_thread::get_id();
}) })
.delayed(one_ms) .delayed(one_ms)
.then([=, &second_task_thread_id] { .thenValue([=, &second_task_thread_id](auto&&) {
second_task_thread_id = std::this_thread::get_id(); second_task_thread_id = std::this_thread::get_id();
return now() - t1; return now() - t1;
}) })
...@@ -320,7 +324,8 @@ TEST(Timekeeper, interruptDoesntCrash) { ...@@ -320,7 +324,8 @@ TEST(Timekeeper, interruptDoesntCrash) {
TEST(Timekeeper, chainedInterruptTest) { TEST(Timekeeper, chainedInterruptTest) {
bool test = false; bool test = false;
auto f = futures::sleep(milliseconds(100)).then([&]() { test = true; }); auto f =
futures::sleep(milliseconds(100)).thenValue([&](auto&&) { test = true; });
f.cancel(); f.cancel();
f.wait(); f.wait();
EXPECT_FALSE(test); EXPECT_FALSE(test);
...@@ -368,7 +373,7 @@ TEST(Timekeeper, executor) { ...@@ -368,7 +373,7 @@ TEST(Timekeeper, executor) {
Promise<Unit> p; Promise<Unit> p;
ExecutorTester tester; ExecutorTester tester;
auto f = p.getFuture().via(&tester).within(one_ms).then([&]() {}); auto f = p.getFuture().via(&tester).within(one_ms).thenValue([&](auto&&) {});
p.setValue(); p.setValue();
f.wait(); f.wait();
EXPECT_EQ(2, tester.count); EXPECT_EQ(2, tester.count);
......
...@@ -67,7 +67,7 @@ TEST(Times, success) { ...@@ -67,7 +67,7 @@ TEST(Times, success) {
auto thunk = makeThunk(ps, interrupt, ps_mutex); auto thunk = makeThunk(ps, interrupt, ps_mutex);
auto f = folly::times(3, thunk) auto f = folly::times(3, thunk)
.then([&]() mutable { complete = true; }) .thenValue([&](auto&&) mutable { complete = true; })
.onError([&](FutureException& /* e */) { failure = true; }); .onError([&](FutureException& /* e */) { failure = true; });
popAndFulfillPromise(ps, ps_mutex); popAndFulfillPromise(ps, ps_mutex);
...@@ -93,7 +93,7 @@ TEST(Times, failure) { ...@@ -93,7 +93,7 @@ TEST(Times, failure) {
auto thunk = makeThunk(ps, interrupt, ps_mutex); auto thunk = makeThunk(ps, interrupt, ps_mutex);
auto f = folly::times(3, thunk) auto f = folly::times(3, thunk)
.then([&]() mutable { complete = true; }) .thenValue([&](auto&&) mutable { complete = true; })
.onError([&](FutureException& /* e */) { failure = true; }); .onError([&](FutureException& /* e */) { failure = true; });
popAndFulfillPromise(ps, ps_mutex); popAndFulfillPromise(ps, ps_mutex);
...@@ -121,7 +121,7 @@ TEST(Times, interrupt) { ...@@ -121,7 +121,7 @@ TEST(Times, interrupt) {
auto thunk = makeThunk(ps, interrupt, ps_mutex); auto thunk = makeThunk(ps, interrupt, ps_mutex);
auto f = folly::times(3, thunk) auto f = folly::times(3, thunk)
.then([&]() mutable { complete = true; }) .thenValue([&](auto&&) mutable { complete = true; })
.onError([&](FutureException& /* e */) { failure = true; }); .onError([&](FutureException& /* e */) { failure = true; });
EXPECT_EQ(0, interrupt); EXPECT_EQ(0, interrupt);
......
...@@ -132,7 +132,7 @@ TEST_F(ViaFixture, threadHops) { ...@@ -132,7 +132,7 @@ TEST_F(ViaFixture, threadHops) {
TEST_F(ViaFixture, chainVias) { TEST_F(ViaFixture, chainVias) {
auto westThreadId = std::this_thread::get_id(); auto westThreadId = std::this_thread::get_id();
auto f = via(eastExecutor.get()) auto f = via(eastExecutor.get())
.then([=]() { .thenValue([=](auto&&) {
EXPECT_NE(std::this_thread::get_id(), westThreadId); EXPECT_NE(std::this_thread::get_id(), westThreadId);
return 1; return 1;
}) })
...@@ -224,14 +224,15 @@ struct PriorityExecutor : public Executor { ...@@ -224,14 +224,15 @@ struct PriorityExecutor : public Executor {
TEST(Via, priority) { TEST(Via, priority) {
PriorityExecutor exe; PriorityExecutor exe;
via(&exe, -1).then([] {}); via(&exe, -1).thenValue([](auto&&) {});
via(&exe, 0).then([] {}); via(&exe, 0).thenValue([](auto&&) {});
via(&exe, 1).then([] {}); via(&exe, 1).thenValue([](auto&&) {});
via(&exe, 42).then([] {}); // overflow should go to max priority via(&exe, 42).thenValue([](auto&&) {}); // overflow should go to max priority
via(&exe, -42).then([] {}); // underflow should go to min priority via(&exe, -42).thenValue(
via(&exe).then([] {}); // default to mid priority [](auto&&) {}); // underflow should go to min priority
via(&exe, Executor::LO_PRI).then([] {}); via(&exe).thenValue([](auto&&) {}); // default to mid priority
via(&exe, Executor::HI_PRI).then([] {}); via(&exe, Executor::LO_PRI).thenValue([](auto&&) {});
via(&exe, Executor::HI_PRI).thenValue([](auto&&) {});
EXPECT_EQ(3, exe.count0); EXPECT_EQ(3, exe.count0);
EXPECT_EQ(2, exe.count1); EXPECT_EQ(2, exe.count1);
EXPECT_EQ(3, exe.count2); EXPECT_EQ(3, exe.count2);
...@@ -261,7 +262,7 @@ TEST_F(ViaFixture, chainX3) { ...@@ -261,7 +262,7 @@ TEST_F(ViaFixture, chainX3) {
return std::string("hello"); return std::string("hello");
}, },
[&] { count++; }) [&] { count++; })
.then([&]() { .thenValue([&](auto&&) {
EXPECT_EQ(std::this_thread::get_id(), westThreadId); EXPECT_EQ(std::this_thread::get_id(), westThreadId);
return makeFuture(42); return makeFuture(42);
}); });
...@@ -272,9 +273,10 @@ TEST_F(ViaFixture, chainX3) { ...@@ -272,9 +273,10 @@ TEST_F(ViaFixture, chainX3) {
TEST(Via, then2) { TEST(Via, then2) {
ManualExecutor x1, x2; ManualExecutor x1, x2;
bool a = false, b = false, c = false; bool a = false, b = false, c = false;
via(&x1).then([&] { a = true; }).then(&x2, [&] { b = true; }).then([&] { via(&x1)
c = true; .thenValue([&](auto&&) { a = true; })
}); .then(&x2, [&](auto&&) { b = true; })
.thenValue([&](auto&&) { c = true; });
EXPECT_FALSE(a); EXPECT_FALSE(a);
EXPECT_FALSE(b); EXPECT_FALSE(b);
...@@ -349,7 +351,9 @@ class ThreadExecutor : public Executor { ...@@ -349,7 +351,9 @@ class ThreadExecutor : public Executor {
TEST(Via, viaThenGetWasRacy) { TEST(Via, viaThenGetWasRacy) {
ThreadExecutor x; ThreadExecutor x;
std::unique_ptr<int> val = std::unique_ptr<int> val =
folly::via(&x).then([] { return std::make_unique<int>(42); }).get(); folly::via(&x)
.thenValue([](auto&&) { return std::make_unique<int>(42); })
.get();
ASSERT_TRUE(!!val); ASSERT_TRUE(!!val);
EXPECT_EQ(42, *val); EXPECT_EQ(42, *val);
} }
...@@ -392,7 +396,7 @@ TEST(Via, getVia) { ...@@ -392,7 +396,7 @@ TEST(Via, getVia) {
{ {
// non-void // non-void
ManualExecutor x; ManualExecutor x;
auto f = via(&x).then([] { return true; }); auto f = via(&x).thenValue([](auto&&) { return true; });
EXPECT_TRUE(f.getVia(&x)); EXPECT_TRUE(f.getVia(&x));
} }
...@@ -422,7 +426,7 @@ TEST(Via, getTryVia) { ...@@ -422,7 +426,7 @@ TEST(Via, getTryVia) {
{ {
// non-void // non-void
ManualExecutor x; ManualExecutor x;
auto f = via(&x).then([] { return 23; }); auto f = via(&x).thenValue([](auto&&) { return 23; });
EXPECT_FALSE(f.isReady()); EXPECT_FALSE(f.isReady());
EXPECT_EQ(23, f.getTryVia(&x).value()); EXPECT_EQ(23, f.getTryVia(&x).value());
} }
...@@ -506,8 +510,8 @@ TEST(Via, viaDummyExecutorFutureSetValueFirst) { ...@@ -506,8 +510,8 @@ TEST(Via, viaDummyExecutorFutureSetValueFirst) {
auto captured_promise_future = captured_promise.getFuture(); auto captured_promise_future = captured_promise.getFuture();
DummyDrivableExecutor x; DummyDrivableExecutor x;
auto future = makeFuture().via(&x).then( auto future = makeFuture().via(&x).thenValue(
[c = std::move(captured_promise)] { return 42; }); [c = std::move(captured_promise)](auto&&) { return 42; });
EXPECT_THROW(std::move(future).get(std::chrono::seconds(5)), BrokenPromise); EXPECT_THROW(std::move(future).get(std::chrono::seconds(5)), BrokenPromise);
EXPECT_THROW( EXPECT_THROW(
...@@ -525,8 +529,8 @@ TEST(Via, viaDummyExecutorFutureSetCallbackFirst) { ...@@ -525,8 +529,8 @@ TEST(Via, viaDummyExecutorFutureSetCallbackFirst) {
DummyDrivableExecutor x; DummyDrivableExecutor x;
Promise<Unit> trigger; Promise<Unit> trigger;
auto future = trigger.getFuture().via(&x).then( auto future = trigger.getFuture().via(&x).thenValue(
[c = std::move(captured_promise)] { return 42; }); [c = std::move(captured_promise)](auto&&) { return 42; });
trigger.setValue(); trigger.setValue();
EXPECT_THROW(std::move(future).get(std::chrono::seconds(5)), BrokenPromise); EXPECT_THROW(std::move(future).get(std::chrono::seconds(5)), BrokenPromise);
...@@ -547,8 +551,8 @@ TEST(Via, viaExecutorDiscardsTaskFutureSetValueFirst) { ...@@ -547,8 +551,8 @@ TEST(Via, viaExecutorDiscardsTaskFutureSetValueFirst) {
Optional<Future<int>> future; Optional<Future<int>> future;
{ {
ManualExecutor x; ManualExecutor x;
future = makeFuture().via(&x).then( future = makeFuture().via(&x).thenValue(
[c = std::move(captured_promise)] { return 42; }); [c = std::move(captured_promise)](auto&&) { return 42; });
x.clear(); x.clear();
} }
...@@ -571,8 +575,8 @@ TEST(Via, viaExecutorDiscardsTaskFutureSetCallbackFirst) { ...@@ -571,8 +575,8 @@ TEST(Via, viaExecutorDiscardsTaskFutureSetCallbackFirst) {
{ {
ManualExecutor x; ManualExecutor x;
Promise<Unit> trigger; Promise<Unit> trigger;
future = trigger.getFuture().via(&x).then( future = trigger.getFuture().via(&x).thenValue(
[c = std::move(captured_promise)] { return 42; }); [c = std::move(captured_promise)](auto&&) { return 42; });
trigger.setValue(); trigger.setValue();
x.clear(); x.clear();
} }
...@@ -629,7 +633,7 @@ TEST(ViaFunc, isSticky) { ...@@ -629,7 +633,7 @@ TEST(ViaFunc, isSticky) {
auto f = via(&x, [&] { count++; }); auto f = via(&x, [&] { count++; });
x.run(); x.run();
std::move(f).then([&] { count++; }); std::move(f).thenValue([&](auto&&) { count++; });
EXPECT_EQ(1, count); EXPECT_EQ(1, count);
x.run(); x.run();
EXPECT_EQ(2, count); EXPECT_EQ(2, count);
...@@ -649,5 +653,9 @@ TEST(ViaFunc, valueKeepAlive) { ...@@ -649,5 +653,9 @@ TEST(ViaFunc, valueKeepAlive) {
TEST(ViaFunc, thenValueKeepAlive) { TEST(ViaFunc, thenValueKeepAlive) {
ManualExecutor x; ManualExecutor x;
EXPECT_EQ(42, via(getKeepAliveToken(&x)).then([] { return 42; }).getVia(&x)); EXPECT_EQ(
42,
via(getKeepAliveToken(&x))
.thenValue([](auto&&) { return 42; })
.getVia(&x));
} }
...@@ -24,7 +24,7 @@ using namespace folly; ...@@ -24,7 +24,7 @@ using namespace folly;
TEST(When, predicateFalse) { TEST(When, predicateFalse) {
int i = 0; int i = 0;
auto thunk = [&] { return makeFuture().then([&] { i += 1; }); }; auto thunk = [&] { return makeFuture().thenValue([&](auto&&) { i += 1; }); };
// false // false
auto f1 = folly::when(false, thunk); auto f1 = folly::when(false, thunk);
...@@ -34,7 +34,7 @@ TEST(When, predicateFalse) { ...@@ -34,7 +34,7 @@ TEST(When, predicateFalse) {
TEST(When, predicateTrue) { TEST(When, predicateTrue) {
int i = 0; int i = 0;
auto thunk = [&] { return makeFuture().then([&] { i += 1; }); }; auto thunk = [&] { return makeFuture().thenValue([&](auto&&) { i += 1; }); };
// true // true
auto f2 = folly::when(true, thunk); auto f2 = folly::when(true, thunk);
......
...@@ -69,7 +69,7 @@ TEST(WhileDo, success) { ...@@ -69,7 +69,7 @@ TEST(WhileDo, success) {
auto pred = makePred(i); auto pred = makePred(i);
auto thunk = makeThunk(ps, interrupt, ps_mutex); auto thunk = makeThunk(ps, interrupt, ps_mutex);
auto f = folly::whileDo(pred, thunk) auto f = folly::whileDo(pred, thunk)
.then([&]() mutable { complete = true; }) .thenValue([&](auto&&) mutable { complete = true; })
.onError([&](FutureException& /* e */) { failure = true; }); .onError([&](FutureException& /* e */) { failure = true; });
popAndFulfillPromise(ps, ps_mutex); popAndFulfillPromise(ps, ps_mutex);
...@@ -97,7 +97,7 @@ TEST(WhileDo, failure) { ...@@ -97,7 +97,7 @@ TEST(WhileDo, failure) {
auto pred = makePred(i); auto pred = makePred(i);
auto thunk = makeThunk(ps, interrupt, ps_mutex); auto thunk = makeThunk(ps, interrupt, ps_mutex);
auto f = folly::whileDo(pred, thunk) auto f = folly::whileDo(pred, thunk)
.then([&]() mutable { complete = true; }) .thenValue([&](auto&&) mutable { complete = true; })
.onError([&](FutureException& /* e */) { failure = true; }); .onError([&](FutureException& /* e */) { failure = true; });
popAndFulfillPromise(ps, ps_mutex); popAndFulfillPromise(ps, ps_mutex);
...@@ -127,7 +127,7 @@ TEST(WhileDo, interrupt) { ...@@ -127,7 +127,7 @@ TEST(WhileDo, interrupt) {
auto pred = makePred(i); auto pred = makePred(i);
auto thunk = makeThunk(ps, interrupt, ps_mutex); auto thunk = makeThunk(ps, interrupt, ps_mutex);
auto f = folly::whileDo(pred, thunk) auto f = folly::whileDo(pred, thunk)
.then([&]() mutable { complete = true; }) .thenValue([&](auto&&) mutable { complete = true; })
.onError([&](FutureException& /* e */) { failure = true; }); .onError([&](FutureException& /* e */) { failure = true; });
EXPECT_EQ(0, interrupt); EXPECT_EQ(0, interrupt);
......
...@@ -39,7 +39,6 @@ param_types = [ ...@@ -39,7 +39,6 @@ param_types = [
"A const&", "A const&",
"A", "A",
"A&", "A&",
"",
] ]
tests = ( tests = (
......
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