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,14 +2010,15 @@ struct TryEquals { ...@@ -2005,14 +2010,15 @@ 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(
if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) { [](const std::tuple<Try<T>, Try<T>>& t) {
return futures::detail::TryEquals<T>::equals( if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) {
std::get<0>(t), std::get<1>(t)); return futures::detail::TryEquals<T>::equals(
} else { std::get<0>(t), std::get<1>(t));
return false; } else {
} return false;
}); }
});
} }
template <class T> template <class T>
......
...@@ -97,11 +97,12 @@ TEST(Collect, collectAll) { ...@@ -97,11 +97,12 @@ 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(
for (auto& f : ts.value()) { [](Try<std::vector<Try<Unit>>>&& ts) {
f.value(); for (auto& f : ts.value()) {
} f.value();
}); }
});
std::shuffle(promises.begin(), promises.end(), rng); std::shuffle(promises.begin(), promises.end(), rng);
for (auto& p : promises) { for (auto& p : promises) {
...@@ -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,14 +664,15 @@ TEST(Collect, collectAllVariadic) { ...@@ -665,14 +664,15 @@ 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))
.then([&](std::tuple<Try<bool>, Try<int>> tup) { .toUnsafeFuture()
flag = true; .then([&](std::tuple<Try<bool>, Try<int>> tup) {
EXPECT_TRUE(std::get<0>(tup).hasValue()); flag = true;
EXPECT_EQ(std::get<0>(tup).value(), true); EXPECT_TRUE(std::get<0>(tup).hasValue());
EXPECT_TRUE(std::get<1>(tup).hasValue()); EXPECT_EQ(std::get<0>(tup).value(), true);
EXPECT_EQ(std::get<1>(tup).value(), 42); EXPECT_TRUE(std::get<1>(tup).hasValue());
}); EXPECT_EQ(std::get<1>(tup).value(), 42);
});
pb.setValue(true); pb.setValue(true);
EXPECT_FALSE(flag); EXPECT_FALSE(flag);
pi.setValue(42); pi.setValue(42);
...@@ -685,14 +685,14 @@ TEST(Collect, collectAllVariadicReferences) { ...@@ -685,14 +685,14 @@ 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);
EXPECT_TRUE(std::get<1>(tup).hasValue()); EXPECT_TRUE(std::get<1>(tup).hasValue());
EXPECT_EQ(std::get<1>(tup).value(), 42); EXPECT_EQ(std::get<1>(tup).value(), 42);
}); });
pb.setValue(true); pb.setValue(true);
EXPECT_FALSE(flag); EXPECT_FALSE(flag);
pi.setValue(42); pi.setValue(42);
...@@ -705,14 +705,15 @@ TEST(Collect, collectAllVariadicWithException) { ...@@ -705,14 +705,15 @@ 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))
.then([&](std::tuple<Try<bool>, Try<int>> tup) { .toUnsafeFuture()
flag = true; .then([&](std::tuple<Try<bool>, Try<int>> tup) {
EXPECT_TRUE(std::get<0>(tup).hasValue()); flag = true;
EXPECT_EQ(std::get<0>(tup).value(), true); EXPECT_TRUE(std::get<0>(tup).hasValue());
EXPECT_TRUE(std::get<1>(tup).hasException()); EXPECT_EQ(std::get<0>(tup).value(), true);
EXPECT_THROW(std::get<1>(tup).value(), eggs_t); EXPECT_TRUE(std::get<1>(tup).hasException());
}); EXPECT_THROW(std::get<1>(tup).value(), eggs_t);
});
pb.setValue(true); pb.setValue(true);
EXPECT_FALSE(flag); EXPECT_FALSE(flag);
pi.setException(eggs); 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