fangrpcstream

package module
v0.0.0-...-d7be14d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 7 Imported by: 0

README

go-fangrpcstream

Documentation

Overview

Package fangrpcstream provides a safe and easy way to implement multiple senders and/or receivers on a single bidirectional gRPC stream.

Index

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]) Close

func (x *Stream[T, Request, Response]) Close() error

func (*Stream[T, Request, Response]) Done

func (x *Stream[T, Request, Response]) Done() <-chan struct{}

func (*Stream[T, Request, Response]) Err

func (x *Stream[T, Request, Response]) Err() error

func (*Stream[T, Request, Response]) Send

func (x *Stream[T, Request, Response]) Send(ctx context.Context, req Request) error

Send will send a message to the stream.

func (*Stream[T, Request, Response]) Shutdown

func (x *Stream[T, Request, Response]) Shutdown(ctx context.Context) error

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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL