stream

package
v0.0.0-...-e06565c Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("no data available")

Functions

This section is empty.

Types

type Stream

type Stream[T any] struct {
	// contains filtered or unexported fields
}

func NewStream

func NewStream[T any](max int) *Stream[T]

func (*Stream[T]) Async

func (r *Stream[T]) Async(fn func(T)) error

Async wraps the stream with a new stream, and allows customized operations

func (*Stream[T]) BeforeClose

func (r *Stream[T]) BeforeClose(f func())

BeforeClose adds a function to be called before the stream is closed

func (*Stream[T]) Close

func (r *Stream[T]) Close()

Close closes the stream

func (*Stream[T]) Filter

func (r *Stream[T]) Filter(f func(T) error)

Filter filters the stream with a function if the function returns an error, the stream will be closed

func (*Stream[T]) IsClosed

func (r *Stream[T]) IsClosed() bool

func (*Stream[T]) Next

func (r *Stream[T]) Next() bool

Next returns true if there are more data to be read and waits for the next data to be available returns false if the stream is closed NOTE: even if the stream is closed, it will return true if there is data available

func (*Stream[T]) OnClose

func (r *Stream[T]) OnClose(f func())

OnClose adds a function to be called when the stream is closed

func (*Stream[T]) Read

func (r *Stream[T]) Read() (T, error)

Read reads buffered data from the stream and it returns error only if the buffer is empty or an error is written to the stream

func (*Stream[T]) Size

func (r *Stream[T]) Size() int

func (*Stream[T]) Write

func (r *Stream[T]) Write(data T) error

Write writes data to the stream, returns error if the buffer is full

func (*Stream[T]) WriteBlocking

func (r *Stream[T]) WriteBlocking(data T)

WriteBlocking writes data to the stream, blocks if the buffer is full until space becomes available

func (*Stream[T]) WriteError

func (r *Stream[T]) WriteError(err error)

WriteError writes an error to the stream

Jump to

Keyboard shortcuts

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