Skip to content

Commit 34c487a

Browse files
committed
executor constraint
Signed-off-by: turuslan <[email protected]>
1 parent 749ee00 commit 34c487a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/coro/spawn.hpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
#include "coro/coro.hpp"
1414

1515
namespace jam {
16-
void coroSpawn(auto &&executor, Coro<void> &&coro) {
16+
template <typename T>
17+
concept CoroSpawnExecutor =
18+
boost::asio::is_executor<T>::value
19+
|| boost::asio::execution::is_executor<T>::value
20+
|| std::is_convertible_v<T, boost::asio::execution_context &>;
21+
22+
void coroSpawn(CoroSpawnExecutor auto &&executor, Coro<void> &&coro) {
1723
boost::asio::co_spawn(std::forward<decltype(executor)>(executor),
1824
std::move(coro),
1925
[](std::exception_ptr e) {
@@ -24,7 +30,7 @@ namespace jam {
2430
}
2531

2632
template <typename T>
27-
void coroSpawn(auto &&executor, Coro<T> &&coro) {
33+
void coroSpawn(CoroSpawnExecutor auto &&executor, Coro<T> &&coro) {
2834
coroSpawn(std::forward<decltype(executor)>(executor),
2935
[coro{std::move(coro)}]() mutable -> Coro<void> {
3036
std::ignore = co_await std::move(coro);
@@ -41,7 +47,7 @@ namespace jam {
4147
* `co_spawn([](args){ ... }(capture))`
4248
* works because arguments are stored in coroutine state.
4349
*/
44-
void coroSpawn(auto &&executor, auto &&f) {
50+
void coroSpawn(CoroSpawnExecutor auto &&executor, auto &&f) {
4551
coroSpawn(std::forward<decltype(executor)>(executor),
4652
[](std::remove_cvref_t<decltype(f)> f) -> Coro<void> {
4753
if constexpr (std::is_void_v<decltype(f().await_resume())>) {

0 commit comments

Comments
 (0)