(Wangle) Fix typo
authorHannes Roth <hannesr@fb.com>
Wed, 20 May 2015 19:10:00 +0000 (12:10 -0700)
committerwoo <woo@fb.com>
Tue, 26 May 2015 18:31:15 +0000 (11:31 -0700)
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
folly/futures/test/FutureTest.cpp

index 980725247f2e09438ea3a0c9e4aae8886e826672..d315b5055e46131e5c0a7675326b38e3da6e4c0f 100644 (file)
@@ -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<ItT>&& t) {
+          [ctx, i](Try<Result>&& t) {
             ctx->promises_[i].setTry(std::move(t));
             // Chain another future onto this one
             spawn(std::move(ctx));
index bff61b0c0b4c1ef78eb81e24f7296cc47351f73f..f6c295e0a75ce8db6791c15a20defef9eb256985 100644 (file)
@@ -690,7 +690,8 @@ TEST(Future, unwrap) {
   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 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<int> input = {1, 2, 3};
     fn(input, 2, 6);
   }
   {
-    // streaming 4 at a time
+    // 4 in-flight at a time
     vector<int> input = {1, 2, 3};
     fn(input, 4, 6);
   }
@@ -718,6 +719,33 @@ TEST(Future, stream) {
     vector<int> input;
     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) {
@@ -1807,7 +1835,7 @@ TEST(Reduce, Chain) {
   }
 }
 
-TEST(Reduce, Streaming) {
+TEST(Reduce, UnorderedReduce) {
   {
     std::vector<Future<int>> fs;
     fs.push_back(makeFuture(1));
@@ -1841,7 +1869,7 @@ TEST(Reduce, Streaming) {
   }
 }
 
-TEST(Reduce, StreamingException) {
+TEST(Reduce, UnorderedReduceException) {
   Promise<int> p1;
   Promise<int> p2;
   Promise<int> p3;