| 100 | // to the thread_pool to compute their response. |
| 101 | template <class Handler> |
| 102 | bool writer(agrpc::GenericServerRPC& rpc, Channel& channel, asio::thread_pool& thread_pool, |
| 103 | const asio::basic_yield_context<Handler>& yield) |
| 104 | { |
| 105 | bool ok{true}; |
| 106 | while (ok) |
| 107 | { |
| 108 | boost::system::error_code ec; |
| 109 | auto buffer = channel.async_receive(yield[ec]); |
| 110 | if (ec) |
| 111 | { |
| 112 | break; |
| 113 | } |
| 114 | // In this example we switch to the thread_pool to compute the response. |
| 115 | asio::post(asio::bind_executor(thread_pool, yield)); |
| 116 | |
| 117 | process_request(buffer); |
| 118 | |
| 119 | // rpc.write() is thread-safe so we can interact with it from the thread_pool. |
| 120 | ok = rpc.write(buffer, yield); |
| 121 | // Now we are back on the main thread. |
| 122 | } |
| 123 | std::cout << "Generic: Server writes completed with: " << std::boolalpha << ok << std::endl; |
| 124 | return ok; |
| 125 | } |
| 126 | |
| 127 | void handle_generic_bidistream_request(agrpc::GrpcContext& grpc_context, agrpc::GenericServerRPC& rpc, |
| 128 | asio::thread_pool& thread_pool, const asio::yield_context& yield) |
no test coverage detected