template <class T>
Future<T> Future<T>::delayed(Duration dur, Timekeeper* tk) {
return collectAll(*this, futures::sleep(dur, tk))
- .then([](std::tuple<Try<T>, Try<Unit>> tup) {
- Try<T>& t = std::get<0>(tup);
- return makeFuture<T>(std::move(t));
- })
- .via(getExecutor());
+ .then([](std::tuple<Try<T>, Try<Unit>> tup) {
+ Try<T>& t = std::get<0>(tup);
+ return makeFuture<T>(std::move(t));
+ });
}
namespace detail {
EXPECT_FALSE(test);
}
-namespace {
-class ExecutorTester : public Executor {
- public:
- void add(Func f) override {
- count++;
- f();
- }
- std::atomic<int> count{0};
+TEST(Timekeeper, executor) {
+ class ExecutorTester : public Executor {
+ public:
+ void add(Func f) override {
+ count++;
+ f();
+ }
+ std::atomic<int> count{0};
};
- }
-
- TEST(Timekeeper, executor) {
- auto f = makeFuture();
- ExecutorTester tester;
- f.via(&tester).within(one_ms).then([&]() {}).wait();
- EXPECT_EQ(2, tester.count);
- }
-
- TEST(Timekeeper, executorSameAfterDelayed) {
- ExecutorTester tester;
- // make sure we're using the same Executor (tester) after delayed returns
- // by comparing the executor count between invocations
- makeFuture()
- .via(&tester)
- .delayed(one_ms)
- .then([&]() { return tester.count.load(); })
- .then([&](int countBefore) {
- EXPECT_EQ(1, tester.count.load() - countBefore);
- })
- .wait();
+
+ auto f = makeFuture();
+ ExecutorTester tester;
+ f.via(&tester).within(one_ms).then([&](){}).wait();
+ EXPECT_EQ(2, tester.count);
}
// TODO(5921764)