Repository: grpc/grpc-go
File: stream_interfaces.go (Go)

Code before:
	// the streaming RPC.
	ServerStream
}

// ClientStreamingClient represents the client side of a client-streaming (many
// requests, one response) RPC. It is generic over both the type of the request
// message stream and the type of the unary response message. It is used in
// generated code.
type ClientStreamingClient[Req any, Res any] interface {
	// Send sends a request message to the server. This method is called repeatedly
	// to send all messages as part of the client’s request stream.
	// The message type is determined by the Req type parameter
	// of the ClientStreamingClient receiver. It returns an error
	// if the message could not be sent.
	Send(*Req) error

	// CloseAndRecv closes the sending side of the request stream and waits for the server
	// to send a unary response message. This method is typically called after
	// sending all request messages to signal the end of the stream and to receive
	// the final response from the server. The response message type is determined
	// by the Res type parameter of the ClientStreamingClient receiver.
	// It returns the received response message and an error if any occurred.
	// The CloseAndRecv method must be called once and only once to complete the RPC.
	CloseAndRecv() (*Res, error)

	// ClientStream represents the basic client-side streaming operations.
	// It provides methods like SendMsg, RecvMsg, etc., for interacting with
	// the streaming RPC.
	ClientStream
}

// ClientStreamingServer represents the server side of a client-streaming (many
// requests, one response) RPC. It is generic over both the type of the request
// message stream and the type of the unary response message. It is used in
// generated code.
type ClientStreamingServer[Req any, Res any] interface {
	// Recv reads a request message from the client. This method is called repeatedly
	// to receive all messages sent by the client as part of the request stream.
	// The message type is determined by the Req type parameter of the
	// ClientStreamingServer receiver.
	// It returns the received message and an error if any occurred.
	// It returns (nil, io.EOF) when the client has finished sending messages.
	Recv() (*Req, error)

	// SendAndClose sends the unary response message to the client and closes
	// the stream. This method is typically called after processing all
	// request messages from the client to send the final response and close
	// the stream. The response type is determined by the Res type parameter
	// of the ClientStreamingServer receiver.
	// It returns an error if the response could not be sent.
	// SendAndClose must be called once and only once to complete the RPC.

Review comment (suggestion):
No need to write inline comments for parent interface `ClientStream` as the actual interface declaration will already have it

Code after:
	// be called directly.
	ServerStream
}

// ClientStreamingClient represents the client side of a client-streaming (many
// requests, one response) RPC. It is generic over both the type of the request
// message stream and the type of the unary response message. It is used in
// generated code.
type ClientStreamingClient[Req any, Res any] interface {
	// Send sends a request message to the server.  The client may call Send
	// multiple times to send multiple messages to the server.  On error, Send
	// aborts the stream.  If the error was generated by the client, the status
	// is returned directly.  Otherwise, io.EOF is returned, and the status of
	// the stream may be discovered using CloseAndRecv().
	Send(*Req) error

	// CloseAndRecv closes the request stream and waits for the server's
	// response.  This method must be called once and only once after sending
	// all request messages.  Any error returned is implemented by the status
	// package.
	CloseAndRecv() (*Res, error)

	// ClientStream is embedded to provide Context, Header, and Trailer
	// functionality.  No other methods in the ClientStream should be called
	// directly.
	ClientStream
}

// ClientStreamingServer represents the server side of a client-streaming (many
// requests, one response) RPC. It is generic over both the type of the request
// message stream and the type of the unary response message. It is used in
// generated code.
//
// To terminate the RPC, call SendAndClose and return nil from the method
// handler or do not call SendAndClose and return an error from the status
// package.
type ClientStreamingServer[Req any, Res any] interface {
	// Recv receives the next request message from the client.  The server may
	// repeatedly call Recv to read messages from the request stream.  If
	// io.EOF is returned, it indicates the client called CloseAndRecv on its
	// ClientStreamingClient.  Any other error indicates the stream was
	// terminated unexpectedly, and the handler method should return, as the
	// stream is no longer usable.
	Recv() (*Req, error)

	// SendAndClose sends a single response message to the client and closes
	// the stream.  This method must be called once and only once after all
	// request messages have been processed.  Recv should not be called after
	// calling SendAndClose.
	SendAndClose(*Res) error