From: James Sedgwick Date: Fri, 16 Jan 2015 14:37:21 +0000 (-0800) Subject: remove outer Try from whenAll/whenN/whenAny callbacks X-Git-Tag: v0.23.0~43 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7887ef2afa255fc67160146ac212bbd55cc75900;p=folly.git 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 --- diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index b45545f9..3b2be169 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -828,8 +828,8 @@ Future Future::within(Duration dur, E e, Timekeeper* tk) { template Future Future::delayed(Duration dur, Timekeeper* tk) { return whenAll(*this, futures::sleep(dur, tk)) - .then([](Try, Try>>&& tup) { - Try& t = std::get<0>(tup.value()); + .then([](std::tuple, Try> tup) { + Try& t = std::get<0>(tup); return makeFuture(std::move(t)); }); } diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index 4fa1c274..dbe0b942 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -713,8 +713,8 @@ TEST(Future, whenAny) { futures.push_back(p.getFuture()); auto anyf = whenAny(futures.begin(), futures.end()) - .then([](Try>>&& f) { - EXPECT_EQ(42, f.value().second.value()); + .then([](pair> p) { + EXPECT_EQ(42, p.second.value()); }); promises[3].setValue(42); @@ -730,8 +730,8 @@ TEST(when, already_completed) { fs.push_back(makeFuture()); whenAll(fs.begin(), fs.end()) - .then([&](Try>>&& t) { - EXPECT_EQ(fs.size(), t.value().size()); + .then([&](vector> ts) { + EXPECT_EQ(fs.size(), ts.size()); }); } { @@ -740,8 +740,7 @@ TEST(when, already_completed) { fs.push_back(makeFuture(i)); whenAny(fs.begin(), fs.end()) - .then([&](Try>>&& t) { - auto& p = t.value(); + .then([&](pair> p) { EXPECT_EQ(p.first, p.second.value()); }); } @@ -757,9 +756,8 @@ TEST(when, whenN) { bool flag = false; size_t n = 3; whenN(futures.begin(), futures.end(), n) - .then([&](Try>>>&& t) { + .then([&](vector>> v) { flag = true; - auto v = t.value(); EXPECT_EQ(n, v.size()); for (auto& tt : v) EXPECT_TRUE(tt.second.hasValue()); @@ -808,13 +806,12 @@ TEST(Future, whenAllVariadic) { Future fi = pi.getFuture(); bool flag = false; whenAll(std::move(fb), std::move(fi)) - .then([&](Try, Try>>&& t) { + .then([&](std::tuple, Try> tup) { flag = true; - EXPECT_TRUE(t.hasValue()); - EXPECT_TRUE(std::get<0>(t.value()).hasValue()); - EXPECT_EQ(std::get<0>(t.value()).value(), true); - EXPECT_TRUE(std::get<1>(t.value()).hasValue()); - EXPECT_EQ(std::get<1>(t.value()).value(), 42); + EXPECT_TRUE(std::get<0>(tup).hasValue()); + EXPECT_EQ(std::get<0>(tup).value(), true); + EXPECT_TRUE(std::get<1>(tup).hasValue()); + EXPECT_EQ(std::get<1>(tup).value(), 42); }); pb.setValue(true); EXPECT_FALSE(flag); @@ -829,13 +826,12 @@ TEST(Future, whenAllVariadicReferences) { Future fi = pi.getFuture(); bool flag = false; whenAll(fb, fi) - .then([&](Try, Try>>&& t) { + .then([&](std::tuple, Try> tup) { flag = true; - EXPECT_TRUE(t.hasValue()); - EXPECT_TRUE(std::get<0>(t.value()).hasValue()); - EXPECT_EQ(std::get<0>(t.value()).value(), true); - EXPECT_TRUE(std::get<1>(t.value()).hasValue()); - EXPECT_EQ(std::get<1>(t.value()).value(), 42); + EXPECT_TRUE(std::get<0>(tup).hasValue()); + EXPECT_EQ(std::get<0>(tup).value(), true); + EXPECT_TRUE(std::get<1>(tup).hasValue()); + EXPECT_EQ(std::get<1>(tup).value(), 42); }); pb.setValue(true); EXPECT_FALSE(flag);