From 3651364b70406ff1c0c2ed2214777038cf1fe526 Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Wed, 20 May 2015 12:10:00 -0700 Subject: [PATCH] (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 --- folly/futures/Future-inl.h | 2 +- folly/futures/test/FutureTest.cpp | 38 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 98072524..d315b505 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -758,7 +758,7 @@ window(Collection input, F func, size_t n) { // Using setCallback_ directly since we don't need the Future ctx->func_(std::move(ctx->input_[i])).setCallback_( // ctx is captured by value - [ctx, i](Try&& t) { + [ctx, i](Try&& t) { ctx->promises_[i].setTry(std::move(t)); // Chain another future onto this one spawn(std::move(ctx)); diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index bff61b0c..f6c295e0 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -690,7 +690,8 @@ TEST(Future, unwrap) { EXPECT_EQ(7, f.value()); } -TEST(Future, stream) { +TEST(Future, window) { + // int -> Future auto fn = [](vector input, size_t window_size, size_t expect) { auto res = reduce( window( @@ -704,12 +705,12 @@ TEST(Future, stream) { EXPECT_EQ(expect, res); }; { - // streaming 2 at a time + // 2 in-flight at a time vector input = {1, 2, 3}; fn(input, 2, 6); } { - // streaming 4 at a time + // 4 in-flight at a time vector input = {1, 2, 3}; fn(input, 4, 6); } @@ -718,6 +719,33 @@ TEST(Future, stream) { vector input; fn(input, 1, 0); } + { + // int -> Future + auto res = reduce( + window( + std::vector({1, 2, 3}), + [](int i) { return makeFuture(); }, + 2), + 0, + [](int sum, const Try& b) { + EXPECT_TRUE(b.hasValue()); + return sum + 1; + }).get(); + EXPECT_EQ(3, res); + } + { + // string -> return Future + auto res = reduce( + window( + std::vector{"1", "2", "3"}, + [](std::string s) { return makeFuture(folly::to(s)); }, + 2), + 0, + [](int sum, const Try& b) { + return sum + *b; + }).get(); + EXPECT_EQ(6, res); + } } TEST(Future, collectAll) { @@ -1807,7 +1835,7 @@ TEST(Reduce, Chain) { } } -TEST(Reduce, Streaming) { +TEST(Reduce, UnorderedReduce) { { std::vector> fs; fs.push_back(makeFuture(1)); @@ -1841,7 +1869,7 @@ TEST(Reduce, Streaming) { } } -TEST(Reduce, StreamingException) { +TEST(Reduce, UnorderedReduceException) { Promise p1; Promise p2; Promise p3; -- 2.34.1