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

Function async_getline

example/cpp14/executors/async_2.cpp:15–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13// A function to asynchronously read a single line from an input stream.
14template <class IoExecutor, class Handler>
15void async_getline(IoExecutor io_ex, std::istream& is, Handler handler)
16{
17 // Track work for the handler's associated executor.
18 auto work_ex = boost::asio::prefer(
19 get_associated_executor(handler, io_ex),
20 execution::outstanding_work.tracked);
21
22 // Post a function object to do the work asynchronously.
23 boost::asio::require(io_ex, execution::blocking.never).execute(
24 [&is, work_ex, handler=std::move(handler)]() mutable
25 {
26 std::string line;
27 std::getline(is, line);
28
29 // Pass the result to the handler, via the associated executor.
30 boost::asio::prefer(work_ex, execution::blocking.possibly).execute(
31 [line=std::move(line), handler=std::move(handler)]() mutable
32 {
33 handler(std::move(line));
34 });
35 });
36}
37
38// A function to asynchronously read multiple lines from an input stream.
39template <class IoExecutor, class Handler>

Callers 1

async_getlinesFunction · 0.70

Calls 5

get_associated_executorFunction · 0.85
handlerClass · 0.85
preferFunction · 0.50
requireFunction · 0.50
executeMethod · 0.45

Tested by

no test coverage detected