| 248 | //------------------------------------------------------------------------------ |
| 249 | |
| 250 | void test_future() |
| 251 | { |
| 252 | boost::asio::io_context io_context; |
| 253 | |
| 254 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 255 | tcp::socket socket = acceptor.accept(); |
| 256 | |
| 257 | // Test our asynchronous operation using the use_future completion token. |
| 258 | // This token causes the operation's initiating function to return a future, |
| 259 | // which may be used to synchronously wait for the result of the operation. |
| 260 | std::future<void> f = async_write_message( |
| 261 | socket, 654.321, boost::asio::use_future); |
| 262 | |
| 263 | io_context.run(); |
| 264 | |
| 265 | try |
| 266 | { |
| 267 | // Get the result of the operation. |
| 268 | f.get(); |
| 269 | std::cout << "Message sent\n"; |
| 270 | } |
| 271 | catch (const std::exception& e) |
| 272 | { |
| 273 | std::cout << "Exception: " << e.what() << "\n"; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | //------------------------------------------------------------------------------ |
| 278 |
no test coverage detected