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