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

Function async_getlines

example/cpp14/executors/async_2.cpp:40–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38// A function to asynchronously read multiple lines from an input stream.
39template <class IoExecutor, class Handler>
40void async_getlines(IoExecutor io_ex, std::istream& is, std::string init, Handler handler)
41{
42 // Track work for the I/O executor.
43 auto io_work_ex = boost::asio::prefer(io_ex,
44 execution::outstanding_work.tracked);
45
46 // Track work for the handler's associated executor.
47 auto handler_work_ex = boost::asio::prefer(
48 get_associated_executor(handler, io_ex),
49 execution::outstanding_work.tracked);
50
51 // Use the associated executor for each operation in the composition.
52 async_getline(io_work_ex, is,
53 bind_executor(handler_work_ex,
54 [io_work_ex, &is, lines=std::move(init), handler=std::move(handler)]
55 (std::string line) mutable
56 {
57 if (line.empty())
58 handler(lines);
59 else
60 async_getlines(io_work_ex, is, lines + line + "\n", std::move(handler));
61 }));
62}
63
64int main()
65{

Callers 1

mainFunction · 0.85

Calls 5

get_associated_executorFunction · 0.85
handlerClass · 0.85
async_getlineFunction · 0.70
preferFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected