From 8900cad8f8156ab4228ee3ace06e998e56b4c0bb Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Fri, 29 May 2015 10:08:22 -0700 Subject: [PATCH] Chain executor in timeout functions 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 | 2 +- folly/futures/test/TimekeeperTest.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 7d106912..c33e5a8d 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -887,7 +887,7 @@ Future Future::within(Duration dur, E e, Timekeeper* tk) { } }); - return ctx->promise.getFuture(); + return ctx->promise.getFuture().via(getExecutor()); } template diff --git a/folly/futures/test/TimekeeperTest.cpp b/folly/futures/test/TimekeeperTest.cpp index badcc305..f9db640d 100644 --- a/folly/futures/test/TimekeeperTest.cpp +++ b/folly/futures/test/TimekeeperTest.cpp @@ -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 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) { -- 2.34.1