| 38 | // A function to asynchronously read multiple lines from an input stream. |
| 39 | template <class IoExecutor, class Handler> |
| 40 | void 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 | |
| 64 | int main() |
| 65 | { |
no test coverage detected