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

Function test_future

example/cpp11/operations/composed_5.cpp:255–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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