util

package
v0.0.0-...-9bfccdf Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadAgain status = iota
	ReadComplete
	Canceled
)

Variables

This section is empty.

Functions

func ServerStreamWithContext

func ServerStreamWithContext(ctx context.Context, stream grpc.ServerStream) grpc.ServerStream

func SplitFullyQualifiedMethodName

func SplitFullyQualifiedMethodName(fqn string) (string, string, bool)

Split '/pkg.Service/Method' into 'pkg.Service' and 'Method'

Types

type StreamBuffer

type StreamBuffer struct {
	// contains filtered or unexported fields
}

StreamBuffer is an in-memory buffer that can simultaneously be written to by a single writer, and read from by multiple readers, such that all readers see the same data.

To read from the buffer, call NewStream(). This returns a channel that streams a copy of the buffer's contents. If there is already data accumulated in the buffer, the channel will begin to read it immediately, then continue to receive any new data written to the buffer until the buffer is closed. Each channel returned by NewStream() receives a copy of the buffer's full contents, regardless of when it was created.

StreamBuffer implements io.WriteCloser. When Close() is called, all stream channels are closed and any subsequent writes to the buffer return io.ErrClosedPipe. After the buffer is closed, calls to NewStream return a channel that will receive the full contents of the buffer, then be closed.

Care should be taken to ensure that the buffer is always closed when no more writes are expected, because the stream channels are expected to be read from until they are closed. Leaving the buffer open will cause all readers to block indefinitely.

func NewStreamBuffer

func NewStreamBuffer() *StreamBuffer

func (*StreamBuffer) Close

func (b *StreamBuffer) Close() error

func (*StreamBuffer) NewStream

func (b *StreamBuffer) NewStream(ctx context.Context) <-chan []byte

func (*StreamBuffer) Write

func (b *StreamBuffer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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