Commit 3651364b authored by Hannes Roth's avatar Hannes Roth Committed by woo

(Wangle) Fix typo

Summary:
This was supposed to be the `Result` type, since it's called on the
Future returned by the lambda.

Test Plan: Added tests for void and different types in vector/lambda.

Reviewed By: mhl@fb.com

Subscribers: folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D2087819

Tasks: 7126300

Signature: t1:2087819:1432142435:72914fa64eff03454774b87a24c426379defab3b

Blame Revision: rFBCODEf229322bc273190a85b5e995dcd8209b1fbf0825
parent eae7495c
...@@ -758,7 +758,7 @@ window(Collection input, F func, size_t n) { ...@@ -758,7 +758,7 @@ window(Collection input, F func, size_t n) {
// Using setCallback_ directly since we don't need the Future // Using setCallback_ directly since we don't need the Future
ctx->func_(std::move(ctx->input_[i])).setCallback_( ctx->func_(std::move(ctx->input_[i])).setCallback_(
// ctx is captured by value // ctx is captured by value
[ctx, i](Try<ItT>&& t) { [ctx, i](Try<Result>&& t) {
ctx->promises_[i].setTry(std::move(t)); ctx->promises_[i].setTry(std::move(t));
// Chain another future onto this one // Chain another future onto this one
spawn(std::move(ctx)); spawn(std::move(ctx));
......
...@@ -690,7 +690,8 @@ TEST(Future, unwrap) { ...@@ -690,7 +690,8 @@ TEST(Future, unwrap) {
EXPECT_EQ(7, f.value()); EXPECT_EQ(7, f.value());
} }
TEST(Future, stream) { TEST(Future, window) {
// int -> Future<int>
auto fn = [](vector<int> input, size_t window_size, size_t expect) { auto fn = [](vector<int> input, size_t window_size, size_t expect) {
auto res = reduce( auto res = reduce(
window( window(
...@@ -704,12 +705,12 @@ TEST(Future, stream) { ...@@ -704,12 +705,12 @@ TEST(Future, stream) {
EXPECT_EQ(expect, res); EXPECT_EQ(expect, res);
}; };
{ {
// streaming 2 at a time // 2 in-flight at a time
vector<int> input = {1, 2, 3}; vector<int> input = {1, 2, 3};
fn(input, 2, 6); fn(input, 2, 6);
} }
{ {
// streaming 4 at a time // 4 in-flight at a time
vector<int> input = {1, 2, 3}; vector<int> input = {1, 2, 3};
fn(input, 4, 6); fn(input, 4, 6);
} }
...@@ -718,6 +719,33 @@ TEST(Future, stream) { ...@@ -718,6 +719,33 @@ TEST(Future, stream) {
vector<int> input; vector<int> input;
fn(input, 1, 0); fn(input, 1, 0);
} }
{
// int -> Future<void>
auto res = reduce(
window(
std::vector<int>({1, 2, 3}),
[](int i) { return makeFuture(); },
2),
0,
[](int sum, const Try<void>& b) {
EXPECT_TRUE(b.hasValue());
return sum + 1;
}).get();
EXPECT_EQ(3, res);
}
{
// string -> return Future<int>
auto res = reduce(
window(
std::vector<std::string>{"1", "2", "3"},
[](std::string s) { return makeFuture<int>(folly::to<int>(s)); },
2),
0,
[](int sum, const Try<int>& b) {
return sum + *b;
}).get();
EXPECT_EQ(6, res);
}
} }
TEST(Future, collectAll) { TEST(Future, collectAll) {
...@@ -1807,7 +1835,7 @@ TEST(Reduce, Chain) { ...@@ -1807,7 +1835,7 @@ TEST(Reduce, Chain) {
} }
} }
TEST(Reduce, Streaming) { TEST(Reduce, UnorderedReduce) {
{ {
std::vector<Future<int>> fs; std::vector<Future<int>> fs;
fs.push_back(makeFuture(1)); fs.push_back(makeFuture(1));
...@@ -1841,7 +1869,7 @@ TEST(Reduce, Streaming) { ...@@ -1841,7 +1869,7 @@ TEST(Reduce, Streaming) {
} }
} }
TEST(Reduce, StreamingException) { TEST(Reduce, UnorderedReduceException) {
Promise<int> p1; Promise<int> p1;
Promise<int> p2; Promise<int> p2;
Promise<int> p3; Promise<int> p3;
......
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