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