[asio-users] Does handler_type need to be used in std::function?
Brought to you by:
chris_kohlhoff
From: peter j. <p.j...@gm...> - 2017-11-30 10:07:55
|
Hello, I've been using Asio for a long time and few months ago I went about to try it with coroutines. I'm quite amazed at how great they work together, but here is something I'm not understanding with respect to converting the yield context into a handler. I.e. it seems to be that one has to follow this exact path: 1. create handler_type by passing yield_context to it 2. create async_result by passing the above handler_type to it 3. create an (e.g. ) std::function handler by passing the above handler_type to it Now, it's obvious that creating handler_type has to be the first step (because it's used as an argument to the other two). But if I switch the steps #2 and #3, I'll see a crash. Here is an example where one can see it: https://gist.github.com/inetic/dc9081baf45ec4b60037#file-async_result-cpp-L29 Equally puzzling is that if I don't do the step #3, but instead just attempt to execute the instance of handler_type created in step #1, I get a crash as well. This crash can be seen in this example: https://gist.github.com/redlizard/cd537ec8f5e278e97293041a73572793#file-cpp And here how simply doing the step #3 and executing the std::function instead of the handler_type fixes it: https://gist.github.com/redlizard/cd537ec8f5e278e97293041a73572793#gistcomment-2272277 Is this a documented behavior, is it a bug, or is it something that is normally obvious to anyone understanding how Boost.Coroutine works? I'm currently using boost version 1.58 (as it's the default with current Ubuntu). Cheers, Peter |