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

Function test_future

example/cpp11/operations/composed_4.cpp:218–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 4

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected