| 226 | //------------------------------------------------------------------------------ |
| 227 | |
| 228 | void test_future() |
| 229 | { |
| 230 | boost::asio::io_context io_context; |
| 231 | |
| 232 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 233 | tcp::socket socket = acceptor.accept(); |
| 234 | |
| 235 | // Test our asynchronous operation using the use_future completion token. |
| 236 | // This token causes the operation's initiating function to return a future, |
| 237 | // which may be used to synchronously wait for the result of the operation. |
| 238 | std::future<void> f = async_write_messages( |
| 239 | socket, "Testing future\r\n", 5, boost::asio::use_future); |
| 240 | |
| 241 | io_context.run(); |
| 242 | |
| 243 | try |
| 244 | { |
| 245 | // Get the result of the operation. |
| 246 | f.get(); |
| 247 | std::cout << "Messages sent\n"; |
| 248 | } |
| 249 | catch (const std::exception& e) |
| 250 | { |
| 251 | std::cout << "Error: " << e.what() << "\n"; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | //------------------------------------------------------------------------------ |
| 256 |
no test coverage detected