| 13 | // A function to asynchronously read a single line from an input stream. |
| 14 | template <class IoExecutor, class Handler> |
| 15 | void 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. |
| 39 | template <class IoExecutor, class Handler> |
no test coverage detected