streamstate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package streamstate contains the serialized state machine backing streams.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed reports that a stream has already closed.
	ErrClosed = errors.New("stream closed")
	// ErrTerminated reports that a terminal event has already been accepted.
	ErrTerminated = errors.New("stream already terminated")
)

Functions

This section is empty.

Types

type CancelTerminal

type CancelTerminal[T, F any] func(error) Terminal[T, F]

CancelTerminal builds the terminal event used when the stream context ends.

type Producer

type Producer[T, F any] struct {
	// contains filtered or unexported fields
}

Producer serializes event delivery and terminal state for a stream.

func NewProducer

func NewProducer[T, F any](ctx context.Context, buffer int, cancel CancelTerminal[T, F]) *Producer[T, F]

NewProducer constructs a producer with the provided event buffer size.

func (*Producer[T, F]) Close

func (p *Producer[T, F]) Close()

Close closes the stream without emitting another event.

func (*Producer[T, F]) Done

func (p *Producer[T, F]) Done() <-chan struct{}

Done closes after the event channel closes.

func (*Producer[T, F]) Emit

func (p *Producer[T, F]) Emit(ctx context.Context, event T) error

Emit sends a non-terminal event.

func (*Producer[T, F]) Err

func (p *Producer[T, F]) Err() error

Err returns the terminal error, if any.

func (*Producer[T, F]) Events

func (p *Producer[T, F]) Events() <-chan T

Events returns the event channel.

func (*Producer[T, F]) Final

func (p *Producer[T, F]) Final() (F, bool)

Final returns the terminal final value, if one was recorded.

func (*Producer[T, F]) Finish

func (p *Producer[T, F]) Finish(ctx context.Context, terminal Terminal[T, F]) error

Finish sends a terminal event.

type Terminal

type Terminal[T, F any] struct {
	Event    T
	Final    F
	HasFinal bool
	Err      error
}

Terminal is the terminal event and recorded outcome for a stream.

Jump to

Keyboard shortcuts

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