Commit f2bdc48d authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Change calls from collectAll to collectAllSemiFuture

Summary: We are changing `folly::collectAll` to return `SemiFuture` rather than `Future` and this is needed as an interim step. After all calls to `collectAll` are changed to `collectAllSemiFuture`, we'll be renaming it back to `collectAll`.

Reviewed By: yfeldblum

Differential Revision: D8157548

fbshipit-source-id: 27b768ac7ff0d6572bde57f01601045a1fd5d5e5
parent fad32186
...@@ -1702,9 +1702,10 @@ void doubleBatchOuterDispatch( ...@@ -1702,9 +1702,10 @@ void doubleBatchOuterDispatch(
} }
} }
folly::collectAll( folly::collectAllSemiFuture(
innerDispatchResultFutures.begin(), innerDispatchResultFutures.begin(),
innerDispatchResultFutures.end()) innerDispatchResultFutures.end())
.toUnsafeFuture()
.then([&](std::vector<Try<std::vector<std::string>>> .then([&](std::vector<Try<std::vector<std::string>>>
innerDispatchResults) { innerDispatchResults) {
for (auto& unit : innerDispatchResults) { for (auto& unit : innerDispatchResults) {
......
...@@ -1495,7 +1495,11 @@ Future<T> reduce(It first, It last, T&& initial, F&& func) { ...@@ -1495,7 +1495,11 @@ Future<T> reduce(It first, It last, T&& initial, F&& func) {
}); });
for (++first; first != last; ++first) { for (++first; first != last; ++first) {
f = collectAll(f, *first).then([sfunc](std::tuple<Try<T>, Try<ItT>>& t) { f = collectAllSemiFuture(f, *first).toUnsafeFuture().then([sfunc](
std::tuple<
Try<T>,
Try<ItT>>&
t) {
return (*sfunc)(std::move(std::get<0>(t).value()), return (*sfunc)(std::move(std::get<0>(t).value()),
// Either return a ItT&& or a Try<ItT>&& depending // Either return a ItT&& or a Try<ItT>&& depending
// on the type of the argument of func. // on the type of the argument of func.
...@@ -1721,7 +1725,8 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) { ...@@ -1721,7 +1725,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 collectAll(*this, futures::sleep(dur, tk)) return collectAllSemiFuture(*this, futures::sleep(dur, tk))
.toUnsafeFuture()
.then([](std::tuple<Try<T>, Try<Unit>> tup) { .then([](std::tuple<Try<T>, Try<Unit>> tup) {
Try<T>& t = std::get<0>(tup); Try<T>& t = std::get<0>(tup);
return makeFuture<T>(std::move(t)); return makeFuture<T>(std::move(t));
...@@ -2005,7 +2010,8 @@ struct TryEquals { ...@@ -2005,7 +2010,8 @@ struct TryEquals {
template <class T> template <class T>
Future<bool> Future<T>::willEqual(Future<T>& f) { Future<bool> Future<T>::willEqual(Future<T>& f) {
return collectAll(*this, f).then([](const std::tuple<Try<T>, Try<T>>& t) { return collectAllSemiFuture(*this, f).toUnsafeFuture().then(
[](const std::tuple<Try<T>, Try<T>>& t) {
if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) { if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) {
return futures::detail::TryEquals<T>::equals( return futures::detail::TryEquals<T>::equals(
std::get<0>(t), std::get<1>(t)); std::get<0>(t), std::get<1>(t));
......
...@@ -97,7 +97,8 @@ TEST(Collect, collectAll) { ...@@ -97,7 +97,8 @@ TEST(Collect, collectAll) {
futures.push_back(p.getFuture()); futures.push_back(p.getFuture());
} }
auto allf = collectAll(futures).then([](Try<std::vector<Try<Unit>>>&& ts) { auto allf = collectAllSemiFuture(futures).toUnsafeFuture().then(
[](Try<std::vector<Try<Unit>>>&& ts) {
for (auto& f : ts.value()) { for (auto& f : ts.value()) {
f.value(); f.value();
} }
...@@ -420,10 +421,8 @@ TEST(Collect, alreadyCompleted) { ...@@ -420,10 +421,8 @@ TEST(Collect, alreadyCompleted) {
fs.push_back(makeFuture()); fs.push_back(makeFuture());
} }
collectAll(fs) collectAllSemiFuture(fs).toUnsafeFuture().then(
.then([&](std::vector<Try<Unit>> ts) { [&](std::vector<Try<Unit>> ts) { EXPECT_EQ(fs.size(), ts.size()); });
EXPECT_EQ(fs.size(), ts.size());
});
} }
{ {
std::vector<Future<int>> fs; std::vector<Future<int>> fs;
...@@ -665,7 +664,8 @@ TEST(Collect, collectAllVariadic) { ...@@ -665,7 +664,8 @@ TEST(Collect, collectAllVariadic) {
Future<bool> fb = pb.getFuture(); Future<bool> fb = pb.getFuture();
Future<int> fi = pi.getFuture(); Future<int> fi = pi.getFuture();
bool flag = false; bool flag = false;
collectAll(std::move(fb), std::move(fi)) collectAllSemiFuture(std::move(fb), std::move(fi))
.toUnsafeFuture()
.then([&](std::tuple<Try<bool>, Try<int>> tup) { .then([&](std::tuple<Try<bool>, Try<int>> tup) {
flag = true; flag = true;
EXPECT_TRUE(std::get<0>(tup).hasValue()); EXPECT_TRUE(std::get<0>(tup).hasValue());
...@@ -685,8 +685,8 @@ TEST(Collect, collectAllVariadicReferences) { ...@@ -685,8 +685,8 @@ TEST(Collect, collectAllVariadicReferences) {
Future<bool> fb = pb.getFuture(); Future<bool> fb = pb.getFuture();
Future<int> fi = pi.getFuture(); Future<int> fi = pi.getFuture();
bool flag = false; bool flag = false;
collectAll(fb, fi) collectAllSemiFuture(fb, fi).toUnsafeFuture().then(
.then([&](std::tuple<Try<bool>, Try<int>> tup) { [&](std::tuple<Try<bool>, Try<int>> tup) {
flag = true; flag = true;
EXPECT_TRUE(std::get<0>(tup).hasValue()); EXPECT_TRUE(std::get<0>(tup).hasValue());
EXPECT_EQ(std::get<0>(tup).value(), true); EXPECT_EQ(std::get<0>(tup).value(), true);
...@@ -705,7 +705,8 @@ TEST(Collect, collectAllVariadicWithException) { ...@@ -705,7 +705,8 @@ TEST(Collect, collectAllVariadicWithException) {
Future<bool> fb = pb.getFuture(); Future<bool> fb = pb.getFuture();
Future<int> fi = pi.getFuture(); Future<int> fi = pi.getFuture();
bool flag = false; bool flag = false;
collectAll(std::move(fb), std::move(fi)) collectAllSemiFuture(std::move(fb), std::move(fi))
.toUnsafeFuture()
.then([&](std::tuple<Try<bool>, Try<int>> tup) { .then([&](std::tuple<Try<bool>, Try<int>> tup) {
flag = true; flag = true;
EXPECT_TRUE(std::get<0>(tup).hasValue()); EXPECT_TRUE(std::get<0>(tup).hasValue());
......
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