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