| 201 | //------------------------------------------------------------------------------ |
| 202 | |
| 203 | void test_future() |
| 204 | { |
| 205 | boost::asio::io_context io_context; |
| 206 | |
| 207 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 208 | tcp::socket socket = acceptor.accept(); |
| 209 | |
| 210 | // Test our asynchronous operation using the use_future completion token. |
| 211 | // This token causes the operation's initiating function to return a future, |
| 212 | // which may be used to synchronously wait for the result of the operation. |
| 213 | std::future<void> f = async_write_message( |
| 214 | socket, "Testing future\r\n", boost::asio::use_future); |
| 215 | |
| 216 | io_context.run(); |
| 217 | |
| 218 | // Get the result of the operation. |
| 219 | try |
| 220 | { |
| 221 | // Get the result of the operation. |
| 222 | f.get(); |
| 223 | std::cout << "Message sent\n"; |
| 224 | } |
| 225 | catch (const std::exception& e) |
| 226 | { |
| 227 | std::cout << "Error: " << e.what() << "\n"; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | //------------------------------------------------------------------------------ |
| 232 |
no test coverage detected