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