mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Add continuable::via to change the invocation chain to the given executor
This commit is contained in:
parent
6bffb44d2b
commit
e2b5fc36fe
@ -434,6 +434,21 @@ public:
|
|||||||
std::forward<E>(executor));
|
std::forward<E>(executor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a continuable_base which continues its invocation through the
|
||||||
|
/// given executor.
|
||||||
|
///
|
||||||
|
/// \returns Returns a continuable_base of the same type.
|
||||||
|
///
|
||||||
|
/// \since 4.2.0
|
||||||
|
template <typename E>
|
||||||
|
auto via(E&& executor) && {
|
||||||
|
return std::move(*this).next(
|
||||||
|
[](auto&&... args) {
|
||||||
|
return make_result(std::forward<decltype(args)>(args)...);
|
||||||
|
},
|
||||||
|
std::forward<E>(executor));
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a continuable_base which will have its signature converted
|
/// Returns a continuable_base which will have its signature converted
|
||||||
/// to the given Args.
|
/// to the given Args.
|
||||||
///
|
///
|
||||||
|
|||||||
@ -47,6 +47,26 @@ TYPED_TEST(single_dimension_tests, are_executor_dispatchable) {
|
|||||||
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(single_dimension_tests, are_executor_dispatchable_via) {
|
||||||
|
bool invoked = false;
|
||||||
|
auto executor = [&](auto&& work) {
|
||||||
|
// We can move the worker object
|
||||||
|
auto local = std::forward<decltype(work)>(work);
|
||||||
|
ASSERT_FALSE(invoked);
|
||||||
|
// We can invoke the worker object
|
||||||
|
std::move(local)();
|
||||||
|
};
|
||||||
|
|
||||||
|
auto chain = this->supply().via(executor).then([&] {
|
||||||
|
ASSERT_FALSE(invoked);
|
||||||
|
invoked = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
||||||
|
|
||||||
|
ASSERT_TRUE(invoked);
|
||||||
|
}
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_executor_exception_resolveable) {
|
TYPED_TEST(single_dimension_tests, are_executor_exception_resolveable) {
|
||||||
auto executor = [&](auto&& work) {
|
auto executor = [&](auto&& work) {
|
||||||
std::forward<decltype(work)>(work).set_exception(supply_test_exception());
|
std::forward<decltype(work)>(work).set_exception(supply_test_exception());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user