Skip to content

Commit d258f20

Browse files
LeeHowesfacebook-github-bot
authored andcommitted
[] Future<T>::then Future<T>::then(not-try-task) -> Future<T>::thenValue(task). - 5/11
Summary: Part of the larger project to modify Future<T>::then to be r-value qualified and use Future<T>::thenTry or Future<T>::thenValue. The goal is to disambiguate folly::Future and to improve type and lifetime safety of Future and its methods. Codemod: future<T>.then(callable with operator()(not-a-try)) to future<T>.thenValue(callable with operator()(not-a-try)). future<T>.then(callable with operator()()) to future<T>.thenValue(callable with operator()(auto&&)). future<T>.then(callable with operator()(auto)) to future<T>.thenValue(callable with operator()(auto)). Reviewed By: Orvid Differential Revision: D9696740 fbshipit-source-id: 9fc199931870bbecfece22ebfaebbda41d4b1d29
1 parent d05f962 commit d258f20

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

rsocket/test/RSocketClientServerTest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ TEST(RSocketClientServer, ConnectManyAsync) {
5858
auto clientFuture =
5959
makeClientAsync(
6060
workers[workerId].getEventBase(), *server->listeningPort())
61-
.then([&executed](std::shared_ptr<rsocket::RSocketClient> client) {
62-
++executed;
63-
return client;
64-
})
61+
.thenValue(
62+
[&executed](std::shared_ptr<rsocket::RSocketClient> client) {
63+
++executed;
64+
return client;
65+
})
6566
.onError([&](folly::exception_wrapper ex) {
6667
LOG(ERROR) << "error: " << ex.what();
6768
++executed;

rsocket/test/RSocketClientTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(RSocketClient, ConnectFails) {
3636
*worker.getEventBase(), std::move(address)));
3737

3838
std::move(client)
39-
.then([&](auto&&) { FAIL() << "the test needs to fail"; })
39+
.thenValue([&](auto&&) { FAIL() << "the test needs to fail"; })
4040
.onError([&](const std::exception&) {
4141
LOG(INFO) << "connection failed as expected";
4242
})

rsocket/test/WarmResumptionTest.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TEST(WarmResumptionTest, SuccessfulResumption) {
4444
}
4545
auto result =
4646
client->disconnect(std::runtime_error("Test triggered disconnect"))
47-
.then([&] { return client->resume(); });
47+
.thenValue([&](auto&&) { return client->resume(); });
4848
EXPECT_NO_THROW(std::move(result).get());
4949
ts->request(3);
5050
ts->awaitTerminalEvent();
@@ -71,8 +71,9 @@ TEST(WarmResumptionTest, FailedResumption1) {
7171
}
7272

7373
client->disconnect(std::runtime_error("Test triggered disconnect"))
74-
.then([&] { return client->resume(); })
75-
.then([] { FAIL() << "Resumption succeeded when it should not"; })
74+
.thenValue([&](auto&&) { return client->resume(); })
75+
.thenValue(
76+
[](auto&&) { FAIL() << "Resumption succeeded when it should not"; })
7677
.onError([listeningPort, &worker](folly::exception_wrapper) {
7778
folly::ScopedEventBaseThread worker2;
7879
auto newClient =
@@ -118,8 +119,9 @@ TEST(WarmResumptionTest, FailedResumption2) {
118119
std::shared_ptr<RSocketClient> newClient;
119120

120121
client->disconnect(std::runtime_error("Test triggered disconnect"))
121-
.then([&] { return client->resume(); })
122-
.then([] { FAIL() << "Resumption succeeded when it should not"; })
122+
.thenValue([&](auto&&) { return client->resume(); })
123+
.thenValue(
124+
[](auto&&) { FAIL() << "Resumption succeeded when it should not"; })
123125
.onError([listeningPort, newTs, &newClient, &worker2](
124126
folly::exception_wrapper) {
125127
newClient =
@@ -162,7 +164,7 @@ TEST(WarmResumptionTest, DifferentEvb) {
162164
}
163165
auto result =
164166
client->disconnect(std::runtime_error("Test triggered disconnect"))
165-
.then([&] { return client->resume(); });
167+
.thenValue([&](auto&&) { return client->resume(); });
166168
EXPECT_NO_THROW(std::move(result).get());
167169
ts->request(3);
168170
ts->awaitTerminalEvent();

rsocket/test/transport/TcpDuplexConnectionTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ makeSingleClientServer(
6060
auto client = std::make_unique<TcpConnectionFactory>(
6161
*clientEvb, SocketAddress("localhost", port, true));
6262
client->connect(ProtocolVersion::Latest, ResumeStatus::NEW_SESSION)
63-
.then([&clientConnection](
64-
ConnectionFactory::ConnectedDuplexConnection connection) {
63+
.thenValue([&clientConnection](
64+
ConnectionFactory::ConnectedDuplexConnection connection) {
6565
clientConnection = std::move(connection.connection);
6666
})
6767
.wait();

0 commit comments

Comments
 (0)