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