mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Additional work on async
This commit is contained in:
parent
a4da3e84ef
commit
b86fe7a255
@ -39,24 +39,30 @@
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
namespace operations {
|
||||
template <typename... SignatureArgs, typename Callable, typename... Args>
|
||||
auto make_async(signature_arg_t<SignatureArgs...>, Callable&& callable,
|
||||
Args&&... args) {
|
||||
|
||||
auto continuation = [](auto&& promise) mutable { promise.set_value(); };
|
||||
|
||||
return base::attorney::create_from(std::move(continuation), //
|
||||
signature_arg_t<Args...>{},
|
||||
util::ownership{});
|
||||
}
|
||||
|
||||
template <typename Callable, typename... Args>
|
||||
auto async(Callable&& callable, Args&&... args) {
|
||||
using result_t = void;
|
||||
using invoker_t =
|
||||
decltype(base::decoration::invoker_of(identify<result_t>{}));
|
||||
return make_async(invoker_t::hint(), std::forward<Callable>(callable),
|
||||
std::forward<Args>(args)...);
|
||||
using result_t =
|
||||
decltype(util::invoke(std::forward<decltype(callable)>(callable),
|
||||
std::forward<decltype(args)>(args)...));
|
||||
|
||||
auto const hint =
|
||||
decltype(base::decoration::invoker_of(identify<result_t>{}))::hint();
|
||||
|
||||
auto continuation = [callable = std::forward<decltype(callable)>(callable),
|
||||
args = std::make_tuple(std::forward<decltype(args)>(
|
||||
args)...)](auto&& promise) mutable {
|
||||
// Select the invoker
|
||||
auto invoker = base::decoration::invoker_of(identify<result_t>{});
|
||||
|
||||
traits::unpack([&](auto&&... args) {
|
||||
// Invoke the promise through the dedicated invoker
|
||||
invoker(std::move(callable), std::forward<decltype(promise)>(promise),
|
||||
std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
};
|
||||
|
||||
return base::attorney::create_from(std::move(continuation), //
|
||||
hint, util::ownership{});
|
||||
}
|
||||
} // namespace operations
|
||||
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
namespace cti {
|
||||
/// \ingroup Operations
|
||||
/// \{
|
||||
|
||||
template <typename Callable, typename... Args>
|
||||
auto async(Callable&& callable, Args&&... args) {
|
||||
return detail::operations::async(std::forward<Callable>(callable),
|
||||
|
||||
@ -23,6 +23,24 @@
|
||||
|
||||
#include <test-continuable.hpp>
|
||||
|
||||
TYPED_TEST(single_dimension_tests, operations_async_) {
|
||||
using namespace cti;
|
||||
|
||||
static int const CANARY = 19372;
|
||||
|
||||
TYPED_TEST(single_dimension_tests, operations_async) {
|
||||
ASSERT_ASYNC_COMPLETION(async([] {
|
||||
//
|
||||
}));
|
||||
|
||||
ASSERT_ASYNC_RESULT(async([] {
|
||||
//
|
||||
return CANARY;
|
||||
}),
|
||||
CANARY);
|
||||
|
||||
ASSERT_ASYNC_RESULT(async([] {
|
||||
//
|
||||
return std::make_tuple(CANARY, 2, CANARY);
|
||||
}),
|
||||
CANARY, 2, CANARY);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user