observationstream

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0, AGPL-3.0 Imports: 2 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 observationstream provides a bounded, producer-owned observation queue without executing consumer code. Consumer panic, timeout, or detachment therefore cannot block producer completion; consumer cancellation and joining remain the responsibility of the layer that owns consumer execution.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCapacity = errors.New("observation stream capacity must be positive")

ErrInvalidCapacity is returned when a stream cannot retain an observation.

Functions

func New

func New[T any](capacity Capacity) (Producer[T], Consumer[T], error)

New creates separate producer and consumer capabilities. Capacity must be positive so every active stream has an explicit bounded retention budget.

Types

type Capacity

type Capacity int

Capacity names the maximum number of observations retained while the consumer is not receiving.

type Completion

type Completion struct {
	Enqueued        uint64
	CapacityDropped uint64
}

Completion is the producer-proven snapshot at the stream's admission cut. Enqueued does not imply that a consumer received or processed an observation.

type Consumer

type Consumer[T any] <-chan T

Consumer is the receive-only capability for a stream. Its direction prevents consumers from publishing observations or closing producer-owned admission.

type Producer

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

Producer owns publication and completion for one stream.

Producer values may be copied; every copy shares the same lifecycle. The zero value is inactive: publication is rejected and completion returns a zero cut.

func (Producer[T]) Complete

func (producer Producer[T]) Complete() Completion

Complete closes admission and the consumer channel at one serialized cut. Every call returns the same producer-proven snapshot. Owners must quiesce all possible publishers before treating that cut as their final lifecycle state.

func (Producer[T]) IsZero

func (producer Producer[T]) IsZero() bool

IsZero reports whether this producer has an active stream capability.

func (Producer[T]) RecordDropped

func (producer Producer[T]) RecordDropped(count uint64)

RecordDropped accounts for observations lost by an upstream bounded producer. The owner transfers this count before completing the shared output stream.

func (Producer[T]) TryPublish

func (producer Producer[T]) TryPublish(observation T) bool

TryPublish retains observation when admission is open and capacity remains. It never waits for the consumer. A false result means either the bounded capacity was exhausted before completion or publication began after the cut.

Jump to

Keyboard shortcuts

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