Chain executor in timeout functions
authorDave Watson <davejwatson@fb.com>
Fri, 29 May 2015 17:08:22 +0000 (10:08 -0700)
committerNoam Lerner <noamler@fb.com>
Wed, 3 Jun 2015 16:51:17 +0000 (09:51 -0700)
Summary: within, onTimeout, etc use the executor of the future if it is set.

Test Plan: added unittest

Reviewed By: hans@fb.com

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

FB internal diff: D2104770

Tasks: 6958727

Signature: t1:2104770:1432773599:a71c00827071bef46e5700de04c7125142e4eb17

folly/futures/Future-inl.h
folly/futures/test/TimekeeperTest.cpp

index 7d106912f4f2727a9529f56a71631b83c258fe12..c33e5a8dfe0090cf7cfcd5b01006c2ff53cb2172 100644 (file)
@@ -887,7 +887,7 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) {
     }
   });
 
-  return ctx->promise.getFuture();
+  return ctx->promise.getFuture().via(getExecutor());
 }
 
 template <class T>
index badcc305db0c0eca45a2b5abe7458c1cfe4cc9e5..f9db640db52f04894194ebe1c7d45188f381678a 100644 (file)
@@ -169,6 +169,22 @@ TEST(Timekeeper, chainedInterruptTest) {
   f.wait();
   EXPECT_FALSE(test);
 }
+
+TEST(Timekeeper, executor) {
+  class ExecutorTester : public Executor {
+   public:
+    void add(Func f) override {
+      count++;
+      f();
+    }
+    std::atomic<int> count{0};
+  };
+
+  auto f = makeFuture();
+  ExecutorTester tester;
+  f.via(&tester).within(std::chrono::milliseconds(1)).then([&](){}).wait();
+  EXPECT_EQ(2, tester.count);
+}
 // TODO(5921764)
 /*
 TEST(Timekeeper, onTimeoutPropagates) {