Skip to content

Commit

Permalink
feat userver/docs: add two coroutines bidirectional stream example
Browse files Browse the repository at this point in the history
554664168b79a4b431cecfe74673cc95d1fa65ac
  • Loading branch information
kopturovdim committed Feb 22, 2024
1 parent 8e1aeee commit fcd5ede
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion grpc/include/userver/ugrpc/client/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class [[nodiscard]] OutputStream final : public CallAnyBase {

/// @brief Controls a request stream -> response stream RPC
///
/// This class allows the following concurrent calls:
/// It is safe to call the following methods from different coroutines:
///
/// - `GetContext`;
/// - one of (`Read`, `ReadAsync`);
Expand Down Expand Up @@ -330,6 +330,27 @@ class [[nodiscard]] OutputStream final : public CallAnyBase {
/// Instead the user SHOULD call `Read` method until the end of input. If
/// `Write` or `WritesDone` finishes with negative result, finally `Read`
/// will throw an exception.
///
/// ## Usage example
///
/// ```cpp
/// auto stream = grpc_client.SomeBidirectionalStreamMethod();
///
/// auto write_task = engine::AsyncNoSpan([&stream, &request_messages] {
/// for (const auto& message : request_messages) {
/// if (!stream.Write(message)) {
/// return;
/// }
/// }
/// stream.WritesDone();
/// });
///
/// while (stream.Read(response_message)) {
/// // ...
/// }
///
/// write_task.Get();
/// ```
template <typename Request, typename Response>
class [[nodiscard]] BidirectionalStream final : public CallAnyBase {
public:
Expand Down

0 comments on commit fcd5ede

Please sign in to comment.