Commit 7887ef2a authored by James Sedgwick's avatar James Sedgwick Committed by woo

remove outer Try from whenAll/whenN/whenAny callbacks

Summary:
it's redundant and we shouldn't encourage it, so i'm changing all callsites
i changed docs as well

Test Plan: wait for contbuild

Reviewed By: hans@fb.com

Subscribers: trunkagent, fbcode-common-diffs@, hero-diffs@, cold-storage-diffs@, targeting-diff-backend@, adityab, everstore-dev@, zhuohuang, darshan, micha, folly-diffs@, wch, lins, tingy, jsedgwick

FB internal diff: D1784667

Tasks: 5936469

Signature: t1:1784667:1421364620:83169739320e5342d28a744e3689794f16108fea
parent b4074536
...@@ -828,8 +828,8 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) { ...@@ -828,8 +828,8 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) {
template <class T> template <class T>
Future<T> Future<T>::delayed(Duration dur, Timekeeper* tk) { Future<T> Future<T>::delayed(Duration dur, Timekeeper* tk) {
return whenAll(*this, futures::sleep(dur, tk)) return whenAll(*this, futures::sleep(dur, tk))
.then([](Try<std::tuple<Try<T>, Try<void>>>&& tup) { .then([](std::tuple<Try<T>, Try<void>> tup) {
Try<T>& t = std::get<0>(tup.value()); Try<T>& t = std::get<0>(tup);
return makeFuture<T>(std::move(t)); return makeFuture<T>(std::move(t));
}); });
} }
......
...@@ -713,8 +713,8 @@ TEST(Future, whenAny) { ...@@ -713,8 +713,8 @@ TEST(Future, whenAny) {
futures.push_back(p.getFuture()); futures.push_back(p.getFuture());
auto anyf = whenAny(futures.begin(), futures.end()) auto anyf = whenAny(futures.begin(), futures.end())
.then([](Try<pair<size_t, Try<int>>>&& f) { .then([](pair<size_t, Try<int>> p) {
EXPECT_EQ(42, f.value().second.value()); EXPECT_EQ(42, p.second.value());
}); });
promises[3].setValue(42); promises[3].setValue(42);
...@@ -730,8 +730,8 @@ TEST(when, already_completed) { ...@@ -730,8 +730,8 @@ TEST(when, already_completed) {
fs.push_back(makeFuture()); fs.push_back(makeFuture());
whenAll(fs.begin(), fs.end()) whenAll(fs.begin(), fs.end())
.then([&](Try<vector<Try<void>>>&& t) { .then([&](vector<Try<void>> ts) {
EXPECT_EQ(fs.size(), t.value().size()); EXPECT_EQ(fs.size(), ts.size());
}); });
} }
{ {
...@@ -740,8 +740,7 @@ TEST(when, already_completed) { ...@@ -740,8 +740,7 @@ TEST(when, already_completed) {
fs.push_back(makeFuture(i)); fs.push_back(makeFuture(i));
whenAny(fs.begin(), fs.end()) whenAny(fs.begin(), fs.end())
.then([&](Try<pair<size_t, Try<int>>>&& t) { .then([&](pair<size_t, Try<int>> p) {
auto& p = t.value();
EXPECT_EQ(p.first, p.second.value()); EXPECT_EQ(p.first, p.second.value());
}); });
} }
...@@ -757,9 +756,8 @@ TEST(when, whenN) { ...@@ -757,9 +756,8 @@ TEST(when, whenN) {
bool flag = false; bool flag = false;
size_t n = 3; size_t n = 3;
whenN(futures.begin(), futures.end(), n) whenN(futures.begin(), futures.end(), n)
.then([&](Try<vector<pair<size_t, Try<void>>>>&& t) { .then([&](vector<pair<size_t, Try<void>>> v) {
flag = true; flag = true;
auto v = t.value();
EXPECT_EQ(n, v.size()); EXPECT_EQ(n, v.size());
for (auto& tt : v) for (auto& tt : v)
EXPECT_TRUE(tt.second.hasValue()); EXPECT_TRUE(tt.second.hasValue());
...@@ -808,13 +806,12 @@ TEST(Future, whenAllVariadic) { ...@@ -808,13 +806,12 @@ TEST(Future, whenAllVariadic) {
Future<int> fi = pi.getFuture(); Future<int> fi = pi.getFuture();
bool flag = false; bool flag = false;
whenAll(std::move(fb), std::move(fi)) whenAll(std::move(fb), std::move(fi))
.then([&](Try<std::tuple<Try<bool>, Try<int>>>&& t) { .then([&](std::tuple<Try<bool>, Try<int>> tup) {
flag = true; flag = true;
EXPECT_TRUE(t.hasValue()); EXPECT_TRUE(std::get<0>(tup).hasValue());
EXPECT_TRUE(std::get<0>(t.value()).hasValue()); EXPECT_EQ(std::get<0>(tup).value(), true);
EXPECT_EQ(std::get<0>(t.value()).value(), true); EXPECT_TRUE(std::get<1>(tup).hasValue());
EXPECT_TRUE(std::get<1>(t.value()).hasValue()); EXPECT_EQ(std::get<1>(tup).value(), 42);
EXPECT_EQ(std::get<1>(t.value()).value(), 42);
}); });
pb.setValue(true); pb.setValue(true);
EXPECT_FALSE(flag); EXPECT_FALSE(flag);
...@@ -829,13 +826,12 @@ TEST(Future, whenAllVariadicReferences) { ...@@ -829,13 +826,12 @@ TEST(Future, whenAllVariadicReferences) {
Future<int> fi = pi.getFuture(); Future<int> fi = pi.getFuture();
bool flag = false; bool flag = false;
whenAll(fb, fi) whenAll(fb, fi)
.then([&](Try<std::tuple<Try<bool>, Try<int>>>&& t) { .then([&](std::tuple<Try<bool>, Try<int>> tup) {
flag = true; flag = true;
EXPECT_TRUE(t.hasValue()); EXPECT_TRUE(std::get<0>(tup).hasValue());
EXPECT_TRUE(std::get<0>(t.value()).hasValue()); EXPECT_EQ(std::get<0>(tup).value(), true);
EXPECT_EQ(std::get<0>(t.value()).value(), true); EXPECT_TRUE(std::get<1>(tup).hasValue());
EXPECT_TRUE(std::get<1>(t.value()).hasValue()); EXPECT_EQ(std::get<1>(tup).value(), 42);
EXPECT_EQ(std::get<1>(t.value()).value(), 42);
}); });
pb.setValue(true); pb.setValue(true);
EXPECT_FALSE(flag); EXPECT_FALSE(flag);
......
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