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