resultstream

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resultstream provides durable, position-addressed result streams.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidQID   = errors.New("invalid result stream qid")
	ErrExpiredQID   = errors.New("result stream qid expired")
	ErrGoneQID      = errors.New("result stream qid no longer exists")
	ErrCapacity     = errors.New("result stream capacity exceeded")
	ErrDisabled     = errors.New("result stream continuation is disabled")
	ErrInvalidScope = errors.New("invalid result stream scope")
)
View Source
var (
	ErrClosed          = errors.New("result stream is closed")
	ErrInvalidPageSize = errors.New("invalid result stream page size")
	ErrInvalidPosition = errors.New("invalid result stream position")
	ErrInvalidated     = errors.New("result stream was invalidated by a data or policy change")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Disabled                 bool
	TTL                      time.Duration
	MaxStreams               int64
	MaxStreamsPerOwner       int64
	MaxPageSize              int
	MaxRetainedBytes         int64
	MaxRetainedBytesPerOwner int64
}

Config bounds process-local durable result streams.

type ExpandFunc

type ExpandFunc func(ctx context.Context, depth int) (rows [][]any, exhausted bool, err error)

ExpandFunc returns the complete ranked prefix available at depth. The returned prefix must preserve every previously returned row at its index.

type Observer

type Observer interface {
	CursorEvent(outcome string)
	CursorUsage(active, retainedBytes int64)
}

Observer receives bounded cursor lifecycle and aggregate usage signals.

type Page

type Page struct {
	Rows      [][]any
	QID       string
	Position  uint64
	Next      uint64
	HasMore   bool
	Total     *uint64
	ExpiresAt time.Time
	Metadata  map[string]any
}

Page is an immutable view of one stream position. Rows must be treated as read-only by adapters.

type Progressive

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

Progressive grows a replayable row prefix only when buffered rows cannot satisfy a pull. Expansion work runs without registry locks.

func NewProgressive

func NewProgressive(initial [][]any, exhausted bool, initialDepth int, expand ExpandFunc) (*Progressive, error)

NewProgressive constructs a progressively expandable stream.

func (*Progressive) Close

func (s *Progressive) Close() error

Close releases references retained by the stream.

func (*Progressive) Pull

func (s *Progressive) Pull(ctx context.Context, position uint64, n int) (*Page, error)

Pull returns at most n rows and performs enough geometric expansion to know whether another row exists.

func (*Progressive) SetRetainedBytesGrowthGuard

func (s *Progressive) SetRetainedBytesGrowthGuard(growthOK func() bool)

SetRetainedBytesGrowthGuard installs admission checked before expansion is published. It is intended for the owning registry.

type Registry

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

Registry owns signed qids and sharded process-local stream entries.

func NewRegistry

func NewRegistry(config Config) (*Registry, error)

NewRegistry constructs a registry with a random signing key and instance ID.

func (*Registry) Close

func (r *Registry) Close()

Close releases every retained stream and rejects future operations.

func (*Registry) Discard

func (r *Registry) Discard(scope Scope, qid string) error

Discard releases the complete stream addressed by any of its qids.

func (*Registry) Pull

func (r *Registry) Pull(ctx context.Context, scope Scope, qid string, n int) (*Page, error)

Pull resolves a signed qid and invokes the stream without holding a registry shard lock.

func (*Registry) ResolveDatabase

func (r *Registry) ResolveDatabase(owner, qid, requested string) (string, error)

ResolveDatabase returns the database bound to a signed qid after validating its authenticated owner. A nonempty requested database must match exactly.

func (*Registry) SetObserver

func (r *Registry) SetObserver(observer Observer)

SetObserver replaces the optional lifecycle observer.

func (*Registry) Start

func (r *Registry) Start(ctx context.Context, scope Scope, stream Stream, n int) (*Page, error)

Start returns the first page and publishes the stream only when more rows are available.

type RetainedBytesGrowthGuard

type RetainedBytesGrowthGuard interface {
	SetRetainedBytesGrowthGuard(func() bool)
}

RetainedBytesGrowthGuard allows a registry to approve retained growth before an expanding stream publishes its new replayable population.

type RetainedBytesReporter

type RetainedBytesReporter interface {
	RetainedBytes() int64
}

RetainedBytesReporter optionally reports memory retained for future pulls.

type Scope

type Scope struct {
	Owner    string
	Database string
}

Scope binds a stream to one authenticated owner and canonical database.

type Stream

type Stream interface {
	Pull(ctx context.Context, position uint64, n int) (*Page, error)
	Close() error
}

Stream returns deterministic pages for explicit positions. Implementations must permit concurrent and repeated Pull calls.

Jump to

Keyboard shortcuts

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