mirror of
https://github.com/Naios/continuable.git
synced 2026-02-11 04:39:50 +08:00
Finish the async implementation
This commit is contained in:
parent
b86fe7a255
commit
60b75a6134
@ -45,20 +45,24 @@ auto async(Callable&& callable, Args&&... args) {
|
|||||||
decltype(util::invoke(std::forward<decltype(callable)>(callable),
|
decltype(util::invoke(std::forward<decltype(callable)>(callable),
|
||||||
std::forward<decltype(args)>(args)...));
|
std::forward<decltype(args)>(args)...));
|
||||||
|
|
||||||
auto const hint =
|
constexpr auto hint =
|
||||||
decltype(base::decoration::invoker_of(identify<result_t>{}))::hint();
|
decltype(base::decoration::invoker_of(identity<result_t>{}))::hint();
|
||||||
|
|
||||||
auto continuation = [callable = std::forward<decltype(callable)>(callable),
|
auto continuation = [callable = std::forward<decltype(callable)>(callable),
|
||||||
args = std::make_tuple(std::forward<decltype(args)>(
|
args = std::make_tuple(std::forward<decltype(args)>(
|
||||||
args)...)](auto&& promise) mutable {
|
args)...)](auto&& promise) mutable {
|
||||||
// Select the invoker
|
|
||||||
auto invoker = base::decoration::invoker_of(identify<result_t>{});
|
|
||||||
|
|
||||||
traits::unpack([&](auto&&... args) {
|
auto invoker = base::decoration::invoker_of(identity<result_t>{});
|
||||||
// Invoke the promise through the dedicated invoker
|
|
||||||
invoker(std::move(callable), std::forward<decltype(promise)>(promise),
|
using promise_t = decltype(promise);
|
||||||
std::forward<decltype(args)>(args)...);
|
|
||||||
});
|
traits::unpack(
|
||||||
|
[&](auto&&... args) {
|
||||||
|
// Invoke the promise through the dedicated invoker
|
||||||
|
invoker(std::move(callable), std::forward<promise_t>(promise),
|
||||||
|
std::forward<decltype(args)>(args)...);
|
||||||
|
},
|
||||||
|
std::move(args));
|
||||||
};
|
};
|
||||||
|
|
||||||
return base::attorney::create_from(std::move(continuation), //
|
return base::attorney::create_from(std::move(continuation), //
|
||||||
|
|||||||
@ -37,6 +37,29 @@
|
|||||||
namespace cti {
|
namespace cti {
|
||||||
/// \ingroup Operations
|
/// \ingroup Operations
|
||||||
/// \{
|
/// \{
|
||||||
|
|
||||||
|
/// Wraps the given callable inside a continuable_base such that it is
|
||||||
|
/// invoked when the asynchronous result is requested to return the result.
|
||||||
|
///
|
||||||
|
/// The behaviour will be equal as when using make_ready_continuable together
|
||||||
|
/// with continuable_base::then, but async is implemented in
|
||||||
|
/// a more efficient way:
|
||||||
|
/// ```cpp
|
||||||
|
/// auto do_sth() {
|
||||||
|
/// return async([] {
|
||||||
|
/// do_sth_more();
|
||||||
|
/// return 0;
|
||||||
|
/// });
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// \param callable The callable type which is invoked on request
|
||||||
|
///
|
||||||
|
/// \param args The arguments which are passed to the callable upon invocation.
|
||||||
|
///
|
||||||
|
/// \returns A continuable_base which asynchronous result type will
|
||||||
|
/// be computated with the same rules as continuable_base::then .
|
||||||
|
///
|
||||||
template <typename Callable, typename... Args>
|
template <typename Callable, typename... Args>
|
||||||
auto async(Callable&& callable, Args&&... args) {
|
auto async(Callable&& callable, Args&&... args) {
|
||||||
return detail::operations::async(std::forward<Callable>(callable),
|
return detail::operations::async(std::forward<Callable>(callable),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user