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