diff --git a/nano/lib/async.hpp b/nano/lib/async.hpp index c7a28a8568..1cc8b0bfc5 100644 --- a/nano/lib/async.hpp +++ b/nano/lib/async.hpp @@ -162,15 +162,15 @@ concept async_task = std::same_as>; // Concept for callables that return an awaitable template -concept async_callable = requires (T t) { +concept async_factory = requires (T t) { { t () } -> std::same_as>; }; -// Concept for tasks that take a condition and return an awaitable +// Concept for callables that take a condition and return an awaitable template -concept async_callable_with_condition = requires (T t, condition & c) { +concept async_factory_with_condition = requires (T t, condition & c) { { t (c) } -> std::same_as>; @@ -192,8 +192,7 @@ class task { } - template - requires async_task || async_callable + template task (nano::async::strand & strand, Func && func) : strand{ strand }, cancellation{ strand } @@ -204,7 +203,18 @@ class task asio::bind_cancellation_slot (cancellation.slot (), asio::use_future)); } - template + template + task (nano::async::strand & strand, Func && func) : + strand{ strand }, + cancellation{ strand } + { + future = asio::co_spawn ( + strand, + func (), + asio::bind_cancellation_slot (cancellation.slot (), asio::use_future)); + } + + template task (nano::async::strand & strand, Func && func) : strand{ strand }, cancellation{ strand },