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

Future::then to Future::thenValue

Summary: then to thenValue to remove calls to deprecated functions.

Reviewed By: Orvid

Differential Revision: D10362133

fbshipit-source-id: e638d24e95c5c6c46d0366eabcd1ff9537421bc6
parent fec6b413
...@@ -255,7 +255,8 @@ TEST(Executor, Runnable) { ...@@ -255,7 +255,8 @@ TEST(Executor, Runnable) {
TEST(Executor, ThrowableThen) { TEST(Executor, ThrowableThen) {
InlineExecutor x; InlineExecutor x;
auto f = Future<Unit>().then([]() { throw std::runtime_error("Faildog"); }); auto f = Future<Unit>().thenValue(
[](auto&&) { throw std::runtime_error("Faildog"); });
/* /*
auto f = Future<Unit>().via(&x).then([](){ auto f = Future<Unit>().via(&x).then([](){
...@@ -295,7 +296,7 @@ TEST(Executor, DoNothingExecutor) { ...@@ -295,7 +296,7 @@ TEST(Executor, DoNothingExecutor) {
DoNothingExecutor x; DoNothingExecutor x;
// Submit future callback to DoNothingExecutor // Submit future callback to DoNothingExecutor
auto f = folly::via(&x).then([] { return 42; }); auto f = folly::via(&x).thenValue([](auto&&) { return 42; });
// Callback function is stored in DoNothingExecutor, but not executed. // Callback function is stored in DoNothingExecutor, but not executed.
EXPECT_FALSE(f.isReady()); EXPECT_FALSE(f.isReady());
......
...@@ -648,11 +648,11 @@ static void removeThreadTest() { ...@@ -648,11 +648,11 @@ static void removeThreadTest() {
TPE fe(2); TPE fe(2);
f = folly::makeFuture() f = folly::makeFuture()
.via(&fe) .via(&fe)
.then([&id1]() { .thenValue([&id1](auto&&) {
burnMs(100)(); burnMs(100)();
id1 = std::this_thread::get_id(); id1 = std::this_thread::get_id();
}) })
.then([&id2]() { .thenValue([&id2](auto&&) {
return 77; return 77;
id2 = std::this_thread::get_id(); id2 = std::this_thread::get_id();
}); });
...@@ -708,11 +708,11 @@ template <typename TPE> ...@@ -708,11 +708,11 @@ template <typename TPE>
void keepAliveTest() { void keepAliveTest() {
auto executor = std::make_unique<TPE>(4); auto executor = std::make_unique<TPE>(4);
auto f = auto f = futures::sleep(std::chrono::milliseconds{100})
futures::sleep(std::chrono::milliseconds{100}) .via(executor.get())
.via(executor.get()) .thenValue([keepAlive = getKeepAliveToken(executor.get())](
.then([keepAlive = getKeepAliveToken(executor.get())] { return 42; }) auto&&) { return 42; })
.semi(); .semi();
executor.reset(); executor.reset();
...@@ -831,11 +831,11 @@ static void WeakRefTest() { ...@@ -831,11 +831,11 @@ static void WeakRefTest() {
TPE fe(1); TPE fe(1);
f = folly::makeFuture() f = folly::makeFuture()
.via(&fe) .via(&fe)
.then([]() { burnMs(100)(); }) .thenValue([](auto&&) { burnMs(100)(); })
.then([&] { ++counter; }) .thenValue([&](auto&&) { ++counter; })
.via(fe.weakRef()) .via(fe.weakRef())
.then([]() { burnMs(100)(); }) .thenValue([](auto&&) { burnMs(100)(); })
.then([&] { ++counter; }); .thenValue([&](auto&&) { ++counter; });
} }
EXPECT_THROW(std::move(*f).get(), folly::BrokenPromise); EXPECT_THROW(std::move(*f).get(), folly::BrokenPromise);
EXPECT_EQ(1, counter); EXPECT_EQ(1, counter);
...@@ -853,12 +853,12 @@ static void virtualExecutorTest() { ...@@ -853,12 +853,12 @@ static void virtualExecutorTest() {
VirtualExecutor ve(fe); VirtualExecutor ve(fe);
f = futures::sleep(100ms) f = futures::sleep(100ms)
.via(&ve) .via(&ve)
.then([&] { .thenValue([&](auto&&) {
++counter; ++counter;
return futures::sleep(100ms); return futures::sleep(100ms);
}) })
.via(&fe) .via(&fe)
.then([&] { ++counter; }) .thenValue([&](auto&&) { ++counter; })
.semi(); .semi();
} }
EXPECT_EQ(1, counter); EXPECT_EQ(1, counter);
......
...@@ -123,7 +123,7 @@ class FutureDAG : public std::enable_shared_from_this<FutureDAG> { ...@@ -123,7 +123,7 @@ class FutureDAG : public std::enable_shared_from_this<FutureDAG> {
collect(dependencies) collect(dependencies)
.via(nodes[handle].executor) .via(nodes[handle].executor)
.then([this, handle] { .thenValue([this, handle](std::vector<Unit>&&) {
nodes[handle].func().then([this, handle](Try<Unit>&& t) { nodes[handle].func().then([this, handle](Try<Unit>&& t) {
nodes[handle].promise.setTry(std::move(t)); nodes[handle].promise.setTry(std::move(t));
}); });
...@@ -134,8 +134,8 @@ class FutureDAG : public std::enable_shared_from_this<FutureDAG> { ...@@ -134,8 +134,8 @@ class FutureDAG : public std::enable_shared_from_this<FutureDAG> {
} }
nodes[sourceHandle].promise.setValue(); nodes[sourceHandle].promise.setValue();
return nodes[sinkHandle].promise.getFuture().then( return nodes[sinkHandle].promise.getFuture().thenValue(
[that = shared_from_this(), sourceHandle, sinkHandle]() { [that = shared_from_this(), sourceHandle, sinkHandle](Unit) {
that->clean_state(sourceHandle, sinkHandle); that->clean_state(sourceHandle, sinkHandle);
}); });
} }
......
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