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

Code before:
 *
 */

package grpc

// ServerStreamingClient represents the client side of a server-streaming (one
// request, many responses) RPC. It is generic over the type of the response
// message. If an error occurs on the stream, it will be returned as an instance
// of the status package. Refer to the status package documentation for more
// details. It is used in generated code.
type ServerStreamingClient[Res any] interface {
	// Recv receives the next message from the server. The client can repeatedly
	// call Recv to read messages from the server-to-client response stream. Recv
	// returns (nil, io.EOF) once the server-to-client stream is completely read.
	Recv() (*Res, error)
	ClientStream
}

// ServerStreamingServer represents the server side of a server-streaming (one
// request, many responses) RPC. It is generic over the type of the response
// message. If an error occurs on the stream, it will be returned as an instance
// of the status package. Refer to the status package documentation for more
// details. End-of-stream for the server-to-client stream is indicated by the
// return of the handler method. It is used in generated code.
type ServerStreamingServer[Res any] interface {
	// Send can send a stream of messages to the client. It may be called multiple
	// times to send multiple messages.
	Send(*Res) error
	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. If an error occurs
// on the stream, it will be returned as an instance of the status package. Refer
// to the status package documentation for more details. It is used in generated code.
type ClientStreamingClient[Req any, Res any] interface {
	// Send sends a request message to the server. The client can repeatedly call
	// Send to send messages as part of the client-to-server request stream.
	Send(*Req) error

	// CloseAndRecv closes the client-to-server request stream and waits for the server's
	// unary response. This method must be called once and only once after sending all
	// request messages to close the stream and receive the final response from the server.
	CloseAndRecv() (*Res, error)
	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. If an error occurs

Review comment (suggestion):
`Server handler may call Send multiple to time send multiple messages to the client`

Code after:
 *
 */

package grpc

// ServerStreamingClient represents the client side of a server-streaming (one
// request, many responses) RPC. It is generic over the type of the response
// message. It is used in generated code.
type ServerStreamingClient[Res any] interface {
	// Recv receives the next response message from the server. The client may
	// repeatedly call Recv to read messages from the response stream.  If
	// io.EOF is returned, the stream has terminated with an OK status.  Any
	// other error is compatible with the status package and indicates the
	// RPC's status code and message.
	Recv() (*Res, error)

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

// ServerStreamingServer represents the server side of a server-streaming (one
// request, many responses) RPC. It is generic over the type of the response
// message. It is used in generated code.
//
// To terminate the response stream, return from the handler method and return
// an error from the status package, or use nil to indicate an OK status code.
type ServerStreamingServer[Res any] interface {
	// Send sends a response message to the client.  The server handler may
	// call Send multiple times to send multiple messages to the client.  An
	// error is returned if the stream was terminated unexpectedly, and the
	// handler method should return, as the stream is no longer usable.
	Send(*Res) error

	// ServerStream is embedded to provide Context, SetHeader, SendHeader, and
	// SetTrailer functionality.  No other methods in the ServerStream should
	// 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().