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

Function test_future

example/cpp14/operations/composed_8.cpp:220–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218//------------------------------------------------------------------------------
219
220void test_future()
221{
222 boost::asio::io_context io_context;
223
224 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
225 tcp::socket socket = acceptor.accept();
226
227 // Test our asynchronous operation using the use_future completion token.
228 // This token causes the operation's initiating function to return a future,
229 // which may be used to synchronously wait for the result of the operation.
230 std::future<void> f = async_write_messages(
231 socket, "Testing future\r\n", 5, boost::asio::use_future);
232
233 io_context.run();
234
235 try
236 {
237 // Get the result of the operation.
238 f.get();
239 std::cout << "Messages sent\n";
240 }
241 catch (const std::exception& e)
242 {
243 std::cout << "Error: " << e.what() << "\n";
244 }
245}
246
247//------------------------------------------------------------------------------
248

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