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