Documentation ¶
Overview ¶
Package fangrpcstream provides a safe and easy way to implement multiple senders and/or receivers on a single bidirectional gRPC stream.
Index ¶
- type Client
- type Factory
- type Stream
- func (x *Stream[T, Request, Response]) Close() error
- func (x *Stream[T, Request, Response]) Done() <-chan struct{}
- func (x *Stream[T, Request, Response]) Err() error
- func (x *Stream[T, Request, Response]) Send(ctx context.Context, req Request) error
- func (x *Stream[T, Request, Response]) Shutdown(ctx context.Context) error
- func (x *Stream[T, Request, Response]) Subscribe(ctx context.Context, target any) context.CancelFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client[Request proto.Message, Response proto.Message] interface { Send(Request) error Recv() (Response, error) grpc.ClientStream }
Client models a bidirectional gRPC stream client, and is implemented by generated gRPC clients.
type Factory ¶
type Factory[T Client[Request, Response], Request proto.Message, Response proto.Message] func(ctx context.Context, opts ...grpc.CallOption) (T, error)
Factory models a method to create a bidirectional gRPC stream client, and is implemented by generated gRPC clients.
type Stream ¶
type Stream[T Client[Request, Response], Request proto.Message, Response proto.Message] struct { // contains filtered or unexported fields }
Stream wraps a bidirectional gRPC stream client, and provides concurrency-friendly methods for sending and receiving messages. It is intended for use in scenarios where there are multiple concurrent senders and/or receivers.
func New ¶
func New[T Client[Request, Response], Request proto.Message, Response proto.Message]( ctx context.Context, factory Factory[T, Request, Response], opts ...grpc.CallOption, ) (*Stream[T, Request, Response], error)
New opens a new Stream.
func (*Stream[T, Request, Response]) Done ¶
func (x *Stream[T, Request, Response]) Done() <-chan struct{}
func (*Stream[T, Request, Response]) Subscribe ¶
func (x *Stream[T, Request, Response]) Subscribe(ctx context.Context, target any) context.CancelFunc
Subscribe accepts any `target` that is a channel which can accept Response values. The returned cancel func MUST be called, unless `ctx` is cancelled. WARNING: Sends to `target` are blocking, and callers must therefore always receive promptly.