stream

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxBytes = 8 << 20

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionHook

type CompletionHook func(summary SessionSummary, events []*Event)

type Config

type Config struct {
	BufferSize     int
	ListenerBuffer int
	DropPolicy     DropPolicy
	MaxBytes       bytesize.Budget
}

type Direction

type Direction int
const (
	DirNA Direction = iota
	DirSend
	DirReceive
)

type DropPolicy

type DropPolicy int
const (
	DropNewest DropPolicy = iota
	DropOldest
	DropListener
)

type Event

type Event struct {
	Kind      Kind
	Direction Direction
	Timestamp time.Time
	Sequence  uint64

	Metadata map[string]string
	Payload  []byte

	SSE SSEMetadata
	WS  WSMetadata
}

func (*Event) Size added in v1.5.0

func (e *Event) Size() int64

type Kind

type Kind int
const (
	KindSSE Kind = iota
	KindWebSocket
	KindGRPC
)

type Listener

type Listener struct {
	C        <-chan *Event
	Cancel   func()
	Snapshot Snapshot
	// contains filtered or unexported fields
}

func (Listener) Dropped added in v1.5.0

func (l Listener) Dropped() uint64

Dropped counts the events this listener never received. Events lost before it subscribed are counted by Snapshot.Evicted instead.

type Manager

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

func NewManager

func NewManager() *Manager

func (*Manager) AddCompletionHook

func (m *Manager) AddCompletionHook(id string, hook CompletionHook) bool

func (*Manager) Cancel

func (m *Manager) Cancel(id string) bool

func (*Manager) Get

func (m *Manager) Get(id string) (SessionSummary, bool)

func (*Manager) List

func (m *Manager) List() []SessionSummary

func (*Manager) Register

func (m *Manager) Register(session *Session) SessionSummary

func (*Manager) Snapshot

func (m *Manager) Snapshot(id string) ([]*Event, bool)

type SSEMetadata

type SSEMetadata struct {
	Index   int
	Name    string
	ID      string
	Comment string
	Retry   int
}

type Session

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

func NewSession

func NewSession(parent context.Context, kind Kind, cfg Config) *Session

func (*Session) Cancel

func (s *Session) Cancel()

func (*Session) Close

func (s *Session) Close(err error)

func (*Session) Context

func (s *Session) Context() context.Context

func (*Session) Done

func (s *Session) Done() <-chan struct{}

func (*Session) Err

func (s *Session) Err() error

func (*Session) EventsSnapshot

func (s *Session) EventsSnapshot() []*Event

func (*Session) ID

func (s *Session) ID() string

func (*Session) Kind

func (s *Session) Kind() Kind

func (*Session) MarkClosing

func (s *Session) MarkClosing()

func (*Session) MarkOpen

func (s *Session) MarkOpen()

func (*Session) Publish

func (s *Session) Publish(evt *Event)

func (*Session) State

func (s *Session) State() (State, error)

func (*Session) StatsSnapshot

func (s *Session) StatsSnapshot() Stats

func (*Session) Subscribe

func (s *Session) Subscribe() Listener

Subscribe returns the events still to come plus a snapshot of the ones already published. A session that has ended hands back a closed channel, so a late subscriber reads the transcript and stops instead of waiting on a listener that nothing will ever write to.

type SessionSummary

type SessionSummary struct {
	ID        string
	Kind      Kind
	State     State
	Err       error
	StartedAt time.Time
	EndedAt   time.Time
}

type Snapshot

type Snapshot struct {
	Events  []*Event
	State   State
	Err     error
	Evicted uint64
}

type State

type State int
const (
	StateConnecting State = iota
	StateOpen
	StateClosing
	StateClosed
	StateFailed
)

type Stats

type Stats struct {
	StartedAt   time.Time
	EndedAt     time.Time
	EventsTotal uint64
	BytesTotal  uint64
	Dropped     uint64
	Evicted     uint64
}

type WSMetadata

type WSMetadata struct {
	Opcode int
	Code   websocket.StatusCode
	Reason string
}

Jump to

Keyboard shortcuts

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