objstream

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 3 Imported by: 0

README

go-objstream

A simple wrapper around a Go channel with helper methods for streaming object / error types.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPipe

func NewPipe[Type any](cap int) (*ReadStream[Type], *WriteStream[Type])

NewPipe creates a new ObjectStream instance returns it cast to both ReadStream and WriteStream, acting as an in-memory pipe.

Types

type ObjectStream

type ObjectStream[Type any] struct {
	// contains filtered or unexported fields
}

ObjectStream wraps a channel to provide helpful methods for sending either object or error types, handling casting and much of the boiler plate that would normally be required. It also provides safe closing for the channel, i.e. repeat calls to .Close() will not panic.

func New

func New[Type any](cap int) *ObjectStream[Type]

New returns a new ObjectStream instance with an underlying channel of given capacity.

func (*ObjectStream[Type]) Cap

func (str *ObjectStream[Type]) Cap() int

Cap returns the underlying channel capacity.

func (*ObjectStream[Type]) Close

func (str *ObjectStream[Type]) Close() bool

Close will safely close the underlying channel, is a noop if already closed.

func (*ObjectStream[Type]) Len

func (str *ObjectStream[Type]) Len() int

Len returns the underlying channel length.

func (*ObjectStream[Type]) Open

func (str *ObjectStream[Type]) Open() bool

Open returns whether underlying channel is open.

func (*ObjectStream[Type]) Recv

func (str *ObjectStream[Type]) Recv() (obj Type, ok bool, err error)

Recv will block until next send down the stream, returning true with obj / err, or false on close.

func (*ObjectStream[Type]) RecvCtx

func (str *ObjectStream[Type]) RecvCtx(ctx context.Context) (obj Type, ok bool, err error)

RecvCtx will perform .Recv(), additionally returning error early in the case that context is cancelled.

func (*ObjectStream[Type]) Send

func (str *ObjectStream[Type]) Send(obj Type)

Send will performing a blocking send of an object type down the stream.

func (*ObjectStream[Type]) SendCtx

func (str *ObjectStream[Type]) SendCtx(ctx context.Context, obj Type) error

SendCtx will perform .Send(), additionally returning error early in the case that context is cancelled.

func (*ObjectStream[Type]) SendErr

func (str *ObjectStream[Type]) SendErr(err error)

SendErr will perform a blocking send of an error type down the stream.

func (*ObjectStream[Type]) SendErrCtx

func (str *ObjectStream[Type]) SendErrCtx(ctx context.Context, err error) error

SendErrCtx will perform .SendErr(), additionally returning error early in the case that context is cancelled.

func (*ObjectStream[Type]) TryRecv

func (str *ObjectStream[Type]) TryRecv() (obj Type, ok bool, err error)

TryRecv will perform a non-blocking .Recv(), returning false in any case that next object is not instantly available.

func (*ObjectStream[Type]) TrySend

func (str *ObjectStream[Type]) TrySend(obj Type) bool

TrySend will perform a non-blocking .Send(), returning false in any case that send is not immediately possible.

func (*ObjectStream[Type]) TrySendErr

func (str *ObjectStream[Type]) TrySendErr(err error) bool

TrySendErr will perform a non-blocking .SendErr(), returning false in any case that send is not immediately possible.

type ReadStream

type ReadStream[Type any] ObjectStream[Type]

ReadStream is a typedef of ObjectStream exposing only the read methods.

func (*ReadStream[Type]) Recv

func (str *ReadStream[Type]) Recv() (obj Type, closed bool, err error)

Recv: see ObjectStream.Recv().

func (*ReadStream[Type]) RecvCtx

func (str *ReadStream[Type]) RecvCtx(ctx context.Context) (obj Type, ok bool, err error)

RecvCtx: see ObjectStream.RecvCtx().

func (*ReadStream[Type]) TryRecv

func (str *ReadStream[Type]) TryRecv() (obj Type, ok bool, err error)

TryRecv: see ObjectStream.TryRecv().

type WriteStream

type WriteStream[Type any] ObjectStream[Type]

WriteStream is a typedef of ObjectStream exposing only the write methods.

func (*WriteStream[Type]) Close

func (str *WriteStream[Type]) Close() bool

Close: see ObjectStream.Close().

func (*WriteStream[Type]) Send

func (str *WriteStream[Type]) Send(obj Type)

Send: see ObjectStream.Send().

func (*WriteStream[Type]) SendCtx

func (str *WriteStream[Type]) SendCtx(ctx context.Context, obj Type) error

SendCtx: see ObjectStream.SendCtx().

func (*WriteStream[Type]) SendErr

func (str *WriteStream[Type]) SendErr(err error)

SendErr: see ObjectStream.SendErr().

func (*WriteStream[Type]) SendErrCtx

func (str *WriteStream[Type]) SendErrCtx(ctx context.Context, err error) error

SendErrCtx: see ObjectStream.SendErrCtx().

func (*WriteStream[Type]) TrySend

func (str *WriteStream[Type]) TrySend(obj Type) (ok bool)

TrySend: see ObjectStream.TrySend().

func (*WriteStream[Type]) TrySendErr

func (str *WriteStream[Type]) TrySendErr(err error) (ok bool)

TrySendErr: see ObjectStream.TrySendErr().

Jump to

Keyboard shortcuts

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