MCPcopy Create free account
hub / github.com/boostorg/asio / test_future

Function test_future

example/cpp11/operations/composed_7.cpp:234–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232//------------------------------------------------------------------------------
233
234void test_future()
235{
236 boost::asio::io_context io_context;
237
238 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
239 tcp::socket socket = acceptor.accept();
240
241 // Test our asynchronous operation using the use_future completion token.
242 // This token causes the operation's initiating function to return a future,
243 // which may be used to synchronously wait for the result of the operation.
244 std::future<void> f = async_write_messages(
245 socket, "Testing future\r\n", 5, boost::asio::use_future);
246
247 io_context.run();
248
249 try
250 {
251 // Get the result of the operation.
252 f.get();
253 std::cout << "Messages sent\n";
254 }
255 catch (const std::exception& e)
256 {
257 std::cout << "Error: " << e.what() << "\n";
258 }
259}
260
261//------------------------------------------------------------------------------
262

Callers 1

mainFunction · 0.70

Calls 4

async_write_messagesFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected