Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc: add docs for generic stream interfaces #7470

Merged
merged 26 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
def75b6
Adding Inline comments for stream interfaces in stream_interfaces.go
janardhanvissa Aug 1, 2024
19dcd9b
Updating the Inline comments for stream interface in detail
janardhanvissa Aug 1, 2024
9795302
Removing Inline comments for parent interfaces(ClientStream,ServerStr…
janardhanvissa Aug 2, 2024
d56889f
Updating the description of stream interfaces in stream_interfaces.go…
janardhanvissa Aug 7, 2024
5b08be9
Updated the description as per the comments
janardhanvissa Aug 8, 2024
fc8da54
Updating the description as per the comments addressed
janardhanvissa Aug 9, 2024
8309894
Updating the description as per the comments addressed
janardhanvissa Aug 11, 2024
2403e3c
Reverting generated code line
janardhanvissa Aug 12, 2024
3874b04
Removing extra space in generated code line
janardhanvissa Aug 12, 2024
5eb8eda
Updated the stream interfaces description as per the documentation an…
janardhanvissa Aug 13, 2024
49eb9d2
Moving error and end of stream to interface docstring
janardhanvissa Aug 14, 2024
1db4de7
dummy commit for re-trigger
janardhanvissa Aug 14, 2024
921241a
Moved bidi handler line to interface docstring, updated the send in s…
janardhanvissa Aug 14, 2024
ed434dc
Fixed linter issues for superfluous-else, increment-decrement, indent…
janardhanvissa Aug 14, 2024
3ea5488
Reverting context-as-argument in server.go
janardhanvissa Aug 14, 2024
7beda74
Merge pull request #1 from janardhanvissa/linter-godoc
janardhanvissa Aug 18, 2024
bd44787
Revert "Optimising the code by fixing var-declaration, indent-error-f…
janardhanvissa Aug 18, 2024
c3dfaaf
Merge pull request #4 from janardhanvissa/revert-1-linter-godoc
janardhanvissa Aug 18, 2024
76cbb5c
Merge branch 'master' of https://github.com/janardhanvissa/grpc-go in…
janardhanvissa Aug 22, 2024
7b41ccd
Formatting comments and updating the docstring
janardhanvissa Aug 22, 2024
a009b7c
Formatting comments
janardhanvissa Aug 22, 2024
ea1eabd
Updated the description by adding newline before the sentence.
janardhanvissa Aug 22, 2024
10122ac
updating file for format description
janardhanvissa Aug 22, 2024
2d54e07
Doc updates
dfawley Aug 28, 2024
335eaee
Remove leading spaces
dfawley Aug 28, 2024
6649fa6
Add comment to explain how to close streams from Servers
dfawley Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions stream_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,35 @@ package grpc
// request, many responses) RPC. It is generic over the type of the response
// message. It is used in generated code.
purnesh42H marked this conversation as resolved.
Show resolved Hide resolved
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
}

Expand All @@ -39,18 +59,51 @@ type ServerStreamingServer[Res any] interface {
// 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

// ServerStream is embedded to provide Context, SetHeader, SendHeader, and
// SetTrailer functionality. No other methods in the ServerStream should
// be called directly.
ServerStream
}

Expand All @@ -59,18 +112,51 @@ type ClientStreamingServer[Req any, Res any] interface {
// request message stream and the type of the response message stream. It is
// used in generated code.
type BidiStreamingClient[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 Recv().
Send(*Req) error

// 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, Trailer, and
// CloseSend functionality. No other methods in the ClientStream should be
// called directly.
ClientStream
}

// BidiStreamingServer represents the server side of a bidirectional-streaming
// (many requests, many responses) RPC. It is generic over both the type of the
// request message stream and the type of the response message stream. It is
// used in generated code.
//
// To terminate the stream, return from the handler method and return
// an error from the status package, or use nil to indicate an OK status code.
type BidiStreamingServer[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 CloseSend on its
// BidiStreamingClient. 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)

// 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
}

Expand Down
Loading