| 305 | //------------------------------------------------------------------------------ |
| 306 | |
| 307 | void test_future() |
| 308 | { |
| 309 | boost::asio::io_context io_context; |
| 310 | |
| 311 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 312 | tcp::socket socket = acceptor.accept(); |
| 313 | |
| 314 | // Test our asynchronous operation using the use_future completion token. |
| 315 | // This token causes the operation's initiating function to return a future, |
| 316 | // which may be used to synchronously wait for the result of the operation. |
| 317 | std::future<void> f = async_write_messages( |
| 318 | socket, "Testing future\r\n", 5, boost::asio::use_future); |
| 319 | |
| 320 | io_context.run(); |
| 321 | |
| 322 | try |
| 323 | { |
| 324 | // Get the result of the operation. |
| 325 | f.get(); |
| 326 | std::cout << "Messages sent\n"; |
| 327 | } |
| 328 | catch (const std::exception& e) |
| 329 | { |
| 330 | std::cout << "Error: " << e.what() << "\n"; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | //------------------------------------------------------------------------------ |
| 335 |
no test coverage detected