Commit 8900cad8 authored by Dave Watson's avatar Dave Watson Committed by Noam Lerner

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
parent 8b9a09ce
......@@ -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>
......
......@@ -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) {
......
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