Commit 12049572 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Add missing container overload of collectAnySemiFuture

Summary: collectAny had this overload, it was missed when collectAnySemiFuture was added.

Reviewed By: mpark

Differential Revision: D18689251

fbshipit-source-id: 1fccd6eca9d4afde46a173842641f14aff78aada
parent a65693ba
......@@ -2425,6 +2425,11 @@ template <class Collection>
auto collectAny(Collection&& c) -> decltype(collectAny(c.begin(), c.end())) {
return collectAny(c.begin(), c.end());
}
template <class Collection>
auto collectAnySemiFuture(Collection&& c)
-> decltype(collectAnySemiFuture(c.begin(), c.end())) {
return collectAnySemiFuture(c.begin(), c.end());
}
/** Similar to collectAny, collectAnyWithoutException return the first Future to
* complete without exceptions. If none of the future complete without
......
......@@ -364,6 +364,33 @@ TEST(Collect, collectAny) {
auto& f = idx_fut.second;
EXPECT_EQ(42, f.value());
}
{
std::vector<Promise<int>> promises(10);
std::vector<SemiFuture<int>> futures;
for (auto& p : promises) {
futures.push_back(p.getSemiFuture());
}
for (auto& f : futures) {
EXPECT_FALSE(f.isReady());
}
auto anyf = collectAnySemiFuture(futures);
/* futures were moved in, so these are invalid now */
EXPECT_FALSE(anyf.isReady());
promises[7].setValue(42);
EXPECT_TRUE(anyf.isReady());
auto& idx_fut = anyf.value();
auto i = idx_fut.first;
EXPECT_EQ(7, i);
auto& f = idx_fut.second;
EXPECT_EQ(42, f.value());
}
// error
{
......
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