This function will read one requests from the client at a time. Note that gRPC only allows calling agrpc::read after a previous read has completed.
| 157 | // This function will read one requests from the client at a time. Note that gRPC only allows calling agrpc::read after |
| 158 | // a previous read has completed. |
| 159 | asio::awaitable<void> reader(BidiStreamingRPC& rpc, Channel& channel) |
| 160 | { |
| 161 | while (true) |
| 162 | { |
| 163 | example::v1::Request request; |
| 164 | if (!co_await rpc.read(request)) |
| 165 | { |
| 166 | // Client is done writing. |
| 167 | break; |
| 168 | } |
| 169 | // Send request to writer. The `max_buffer_size` of the channel acts as backpressure. |
| 170 | (void)co_await channel.async_send(boost::system::error_code{}, std::move(request), |
| 171 | asio::as_tuple(asio::use_awaitable)); |
| 172 | } |
| 173 | // Signal the writer to complete. |
| 174 | channel.close(); |
| 175 | } |
| 176 | |
| 177 | // The writer will pick up reads from the reader through the channel and switch to the thread_pool to compute their |
| 178 | // response. |
no test coverage detected