RPP's based implementation for grpc client bidirectional reactor.
To use it you need:
- create it via new operator
- pass it to stub->async()->GrpcBidirectionalStream(ctx, reactor);
- call reactor->init() method for actual starting of grpc logic
- to access values FROM stream you can subscribe to observable obtained via reactor->get_observable() (same observable WOULD emit on_completed in case of successful stream termination and on_error in case of some errors with grpc stream)
- to pass values TO stream you can emit values to observer obtained via reactor->get_observer()
- Warning
- After init() the call may end at any moment (connection refused, deadline, cancel) and the reactor deletes itself in OnDone. Obtain the observer and emit the first values before init(): they are posted and sent once the call starts. Emitting from outside the reactor's callbacks after init() races with the end of the call (gRPC requires a hold for that, see grpc::ClientBidiReactor::AddHold).
auto channel = grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials());
auto stub = TestService::NewStub(channel);
grpc::ClientContext ctx{};
stub->async()->Bidirectional(&ctx, reactor);
reactor->get_observable().subscribe([](const Response&) { });
reactor->get_observer().on_next(Request{});
reactor->init();
- Examples
- client_reactor.cpp.