| 206 | //------------------------------------------------------------------------------ |
| 207 | |
| 208 | void test_future() |
| 209 | { |
| 210 | boost::asio::io_context io_context; |
| 211 | |
| 212 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 213 | tcp::socket socket = acceptor.accept(); |
| 214 | |
| 215 | // Test our asynchronous operation using the use_future completion token. |
| 216 | // This token causes the operation's initiating function to return a future, |
| 217 | // which may be used to synchronously wait for the result of the operation. |
| 218 | std::future<void> f = async_write_message( |
| 219 | socket, "", boost::asio::use_future); |
| 220 | |
| 221 | io_context.run(); |
| 222 | |
| 223 | try |
| 224 | { |
| 225 | // Get the result of the operation. |
| 226 | f.get(); |
| 227 | std::cout << "Message sent\n"; |
| 228 | } |
| 229 | catch (const std::exception& e) |
| 230 | { |
| 231 | std::cout << "Exception: " << e.what() << "\n"; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | //------------------------------------------------------------------------------ |
| 236 |
no test coverage detected