diff --git a/include/continuable/detail/operations/async.hpp b/include/continuable/detail/operations/async.hpp index e9cccd9..61a3271 100644 --- a/include/continuable/detail/operations/async.hpp +++ b/include/continuable/detail/operations/async.hpp @@ -39,24 +39,30 @@ namespace cti { namespace detail { namespace operations { -template -auto make_async(signature_arg_t, Callable&& callable, - Args&&... args) { - - auto continuation = [](auto&& promise) mutable { promise.set_value(); }; - - return base::attorney::create_from(std::move(continuation), // - signature_arg_t{}, - util::ownership{}); -} - template auto async(Callable&& callable, Args&&... args) { - using result_t = void; - using invoker_t = - decltype(base::decoration::invoker_of(identify{})); - return make_async(invoker_t::hint(), std::forward(callable), - std::forward(args)...); + using result_t = + decltype(util::invoke(std::forward(callable), + std::forward(args)...)); + + auto const hint = + decltype(base::decoration::invoker_of(identify{}))::hint(); + + auto continuation = [callable = std::forward(callable), + args = std::make_tuple(std::forward( + args)...)](auto&& promise) mutable { + // Select the invoker + auto invoker = base::decoration::invoker_of(identify{}); + + traits::unpack([&](auto&&... args) { + // Invoke the promise through the dedicated invoker + invoker(std::move(callable), std::forward(promise), + std::forward(args)...); + }); + }; + + return base::attorney::create_from(std::move(continuation), // + hint, util::ownership{}); } } // namespace operations diff --git a/include/continuable/operations/async.hpp b/include/continuable/operations/async.hpp index 02320c7..967f3c0 100644 --- a/include/continuable/operations/async.hpp +++ b/include/continuable/operations/async.hpp @@ -37,7 +37,6 @@ namespace cti { /// \ingroup Operations /// \{ - template auto async(Callable&& callable, Args&&... args) { return detail::operations::async(std::forward(callable), diff --git a/test/unit-test/multi/test-continuable-operations-async.cpp b/test/unit-test/multi/test-continuable-operations-async.cpp index 9ed7fb5..884a2f4 100644 --- a/test/unit-test/multi/test-continuable-operations-async.cpp +++ b/test/unit-test/multi/test-continuable-operations-async.cpp @@ -23,6 +23,24 @@ #include -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); }