| 8 | |
| 9 | |
| 10 | int main() |
| 11 | { |
| 12 | auto channel = grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()); |
| 13 | if (!channel) |
| 14 | { |
| 15 | std::cout << "NO CHANNEL" << std::endl; |
| 16 | return 0; |
| 17 | } |
| 18 | auto stub = TestService::NewStub(channel); |
| 19 | if (!stub) |
| 20 | { |
| 21 | std::cout << "NO STUB" << std::endl; |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | std::array<grpc::ClientContext, 3> ctx{}; |
| 26 | auto d = rpp::composite_disposable_wrapper::make(); |
| 27 | |
| 28 | rpp::subjects::publish_subject<std::string> bidi_requests{}; |
| 29 | rpp::subjects::publish_subject<Response> bidi_responses{}; |
| 30 | bidi_responses.get_observable().subscribe(d, [](const Response& v) { |
| 31 | std::cout << "[BidireactionalResponse]: " << v.ShortDebugString() << std::endl; |
| 32 | }); |
| 33 | |
| 34 | rppgrpc::add_client_reactor(&TestService::StubInterface::async_interface::Bidirectional, |
| 35 | *stub->async(), |
| 36 | &ctx[0], |
| 37 | bidi_requests.get_observable() |
| 38 | | rpp::ops::take_while([](const std::string& v) { return v != "0"; }) |
| 39 | | rpp::ops::map([](const std::string& v) { |
| 40 | Request i{}; |
| 41 | i.set_value(std::string{"BidiRequest "} + v); |
| 42 | return i; |
| 43 | }), |
| 44 | bidi_responses.get_observer()); |
| 45 | |
| 46 | rppgrpc::add_client_reactor(&TestService::StubInterface::async_interface::ClientSide, |
| 47 | *stub->async(), |
| 48 | &ctx[1], |
| 49 | bidi_responses.get_observable() |
| 50 | | rpp::ops::map([](const Response& response) { |
| 51 | Request request{}; |
| 52 | request.set_value(std::string{"ClientSideRequest "} + response.value()); |
| 53 | return request; |
| 54 | }), |
| 55 | rpp::make_lambda_observer(d, [](const Response& v) { |
| 56 | std::cout << "[ClientsideResponse]: " << v.ShortDebugString() << std::endl; |
| 57 | })); |
| 58 | Request req{}; |
| 59 | rppgrpc::add_client_reactor(&TestService::StubInterface::async_interface::ServerSide, |
| 60 | *stub->async(), |
| 61 | &ctx[2], |
| 62 | &req, |
| 63 | rpp::make_lambda_observer(d, [](const Response& v) { |
| 64 | std::cout << "[ServerSideResponse]: " << v.ShortDebugString() << std::endl; |
| 65 | })); |
| 66 | |
| 67 | std::cout << "SUBSCRIBED" << std::endl; |
nothing calls this directly
no test coverage detected