Opened 5 years ago

Closed 5 years ago

#9442 closed Bugs (fixed)

boost::asio::spawn does nothing when coroutines v2 are enabled

Reported by: drigh@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:


Following code works as expected (i.e. prints 'works'). However, it prints nothing if you uncomment lines that enable (or try to enable) use of coroutines v2 in spawn.

#include <iostream>
#include <functional>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

void foo(boost::asio::yield_context ctx)
    std::cout << "works!" << std::endl;

int main()
    boost::asio::io_service srv;

    boost::asio::spawn(srv, std::bind(foo, std::placeholders::_1));;

I am not sure if asio is intentionally not using new coroutines interface by default, but this seems pretty important thing going forward.

Change History (3)

comment:1 Changed 5 years ago by drigh@…

this is my fix on top of boost 1.55.0:

diff --git a/boost/asio/spawn.hpp b/boost/asio/spawn.hpp
index 0d7ee77..232e2e0 100644
--- a/boost/asio/spawn.hpp
+++ b/boost/asio/spawn.hpp
@@ -54,12 +54,12 @@ public:
    * When using Boost.Coroutine v1, this type is:
    * @code typename coroutine<void()> @endcode
    * When using Boost.Coroutine v2 (unidirectional coroutines), this type is:
-   * @code push_coroutine<void> @endcode
+   * @code pull_coroutine<void> @endcode
   typedef implementation_defined callee_type;
-  typedef boost::coroutines::push_coroutine<void> callee_type;
+  typedef boost::coroutines::pull_coroutine<void> callee_type;
   typedef boost::coroutines::coroutine<void()> callee_type;
@@ -69,12 +69,12 @@ public:
    * When using Boost.Coroutine v1, this type is:
    * @code typename coroutine<void()>::caller_type @endcode
    * When using Boost.Coroutine v2 (unidirectional coroutines), this type is:
-   * @code pull_coroutine<void> @endcode
+   * @code push_coroutine<void> @endcode
   typedef implementation_defined caller_type;
-  typedef boost::coroutines::pull_coroutine<void> caller_type;
+  typedef boost::coroutines::push_coroutine<void> caller_type;
   typedef boost::coroutines::coroutine<void()>::caller_type caller_type;

not entirely sure it'll work, but it definitely seems to

comment:2 Changed 5 years ago by anonymous

It is typo here in asio code:


should be


comment:3 Changed 5 years ago by chris_kohlhoff

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.