Created
March 4, 2018 14:43
-
-
Save nlyan/0613fec0bbd13e6d12d19ac1f7c195df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename BufferSequence> | |
auto | |
async_write (tcp::socket& socket, BufferSequence const& buffers) { | |
struct Awaitable { | |
tcp::socket& socket; | |
BufferSequence const& buffers; | |
boost::system::error_code ec; | |
bool | |
await_ready () { | |
return false; | |
} | |
void | |
await_suspend (std::experimental::coroutine_handle<> coro) { | |
return asio::async_write ( | |
socket, | |
buffers, | |
[this, coro](auto ec, std::size_t bytes_written) mutable { | |
if (ec) { | |
this->ec = ec; | |
} | |
coro.resume (); | |
}); | |
} | |
auto | |
await_resume () { | |
return ec; | |
} | |
}; | |
return Awaitable{socket, buffers}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment