queue

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 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 queue adapts ChannX to typed event streams, with atomic admission and explicit drain/abort lifecycle. Each Queue owns one ChannX instance.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNil          = errors.New("queue: nil receiver")
	ErrNilContext   = errors.New("queue: nil context")
	ErrClosed       = errors.New("queue: closed")
	ErrInvalidBytes = errors.New("queue: negative byte estimate")
	ErrSizeOverflow = errors.New("queue: byte estimate overflow")
)

Functions

This section is empty.

Types

type Item

type Item[T any] struct {
	Value T
	Bytes int64
}

Item supplies a value and its caller-estimated retained size. Bytes does not impose a memory limit or account for the queue's own allocations.

type Queue

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

Queue is a dynamically growing event FIFO whose zero value is ready for use. It must not be copied after first use. Growth is limited by available memory; delivery is not persistent. Admission is serialized, and Pop calls share one cancellable consumer token. Only the owner goroutine writes to or closes the underlying ChannX. Callers must Close and drain, or Abort, when finished.

func (*Queue[T]) Abort

func (q *Queue[T]) Abort(cause error) error

Abort wakes waiting Pops, closes admission through the owner, and discards pending envelopes until ChannX terminates. It is O(backlog), independent of an external consumer, and preserves an earlier Close's cause.

func (*Queue[T]) Close

func (q *Queue[T]) Close(cause error) error

Close rejects further admission and requests the owner to close ChannX after all acknowledged pushes. It does not wait for consumer drain. The first cause is preserved; a nil cause becomes io.EOF. Drain or Abort to release resources.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop(ctx context.Context) (T, error)

Pop waits for a value or terminal cause. Cancellation cancels only this wait; even an envelope fetched concurrently with cancellation remains available to the next Pop. Nil contexts are invalid.

func (*Queue[T]) Push

func (q *Queue[T]) Push(value T, bytes int64) error

Push admits one value without waiting for an event consumer.

func (*Queue[T]) PushBatch

func (q *Queue[T]) PushBatch(items []Item[T]) error

PushBatch admits all items as one envelope, contiguously, or rejects the entire batch. Its acknowledgement waits for ChannX admission, never consumer drain.

func (*Queue[T]) Stats

func (q *Queue[T]) Stats() Stats

Stats returns a concurrent snapshot. A nil queue is closed and empty.

type Stats

type Stats struct {
	Items     int
	Bytes     int64
	OldestAge time.Duration
	Closed    bool
}

Stats describes pending values, excluding popped values. OldestAge is always zero: ChannX does not expose the oldest buffered envelope.

Jump to

Keyboard shortcuts

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