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

Function test_future

example/cpp11/operations/composed_6.cpp:316–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314//------------------------------------------------------------------------------
315
316void test_future()
317{
318 boost::asio::io_context io_context;
319
320 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
321 tcp::socket socket = acceptor.accept();
322
323 // Test our asynchronous operation using the use_future completion token.
324 // This token causes the operation's initiating function to return a future,
325 // which may be used to synchronously wait for the result of the operation.
326 std::future<void> f = async_write_messages(
327 socket, "Testing future\r\n", 5, boost::asio::use_future);
328
329 io_context.run();
330
331 try
332 {
333 // Get the result of the operation.
334 f.get();
335 std::cout << "Messages sent\n";
336 }
337 catch (const std::exception& e)
338 {
339 std::cout << "Error: " << e.what() << "\n";
340 }
341}
342
343//------------------------------------------------------------------------------
344

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