c++ – prevent initial suspend of boost awaitable
If the scope that denotes the lifetime of the message object is in a coroutine, and you co_await the sending coroutine within that scope, then you won’t have a dangling reference.
If that isn’t the case, then you will have to wrap the message sending coroutine in a coroutine with a different return type than boost::asio::awaitable, where the wrapping coroutine doesn’t suspend at entry, and you copy or move the message into a local variable before co_awaiting the inner coroutine.
Read more here: Source link
