});
}
-template <class T>
-template <class... Args>
-auto Future<T>::then(Executor* x, Args&&... args)
- -> decltype(this->then(std::forward<Args>(args)...))
-{
- auto oldX = getExecutor();
- setExecutor(x);
- return this->then(std::forward<Args>(args)...).via(oldX);
-}
-
template <class T>
Future<void> Future<T>::then() {
return then([] (Try<T>&& t) {});
Future<typename isFuture<R>::Inner>
then(R(Caller::*func)(Args...), Caller *instance);
- /// Execute the callback via the given Executor. The executor doesn't stick.
- ///
- /// Contrast
- ///
- /// f.via(x).then(b).then(c)
- ///
- /// with
- ///
- /// f.then(x, b).then(c)
- ///
- /// In the former both b and c execute via x. In the latter, only b executes
- /// via x, and c executes via the same executor (if any) that f had.
- template <class... Args>
- auto then(Executor* x, Args&&... args)
- -> decltype(this->then(std::forward<Args>(args)...));
-
/// Convenience method for ignoring the value and creating a Future<void>.
/// Exceptions still propagate.
Future<void> then();
EXPECT_EQ(42, f.get());
EXPECT_EQ(3, count);
}
-
-TEST(Via, then2) {
- ManualExecutor x1, x2;
- bool a,b,c;
- via(&x1)
- .then([&]{ a = true; })
- .then(&x2, [&]{ b = true; })
- .then([&]{ c = true; });
-
- EXPECT_FALSE(a);
- EXPECT_FALSE(b);
-
- x1.run();
- EXPECT_TRUE(a);
- EXPECT_FALSE(b);
- EXPECT_FALSE(c);
-
- x2.run();
- EXPECT_TRUE(b);
- EXPECT_FALSE(c);
-
- x1.run();
- EXPECT_TRUE(c);
-}
-
-TEST(Via, then2Variadic) {
- struct Foo { void foo(Try<void>) {} };
- Foo f;
- makeFuture().then(nullptr, &Foo::foo, &f);
-}