operations

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 3 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 operations tracks external outcomes without executing or retrying work Serialize calls on the owner loop or with a caller-held mutex. Values are immutable snapshots; cost is a caller-supplied logical retained-byte bound

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ledger

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

func New

func New[T any](capacity, bytes int) (*Ledger[T], error)

Create a count- and byte-bounded operation ledger

func (*Ledger[T]) Bytes

func (l *Ledger[T]) Bytes() int

Return the logical bytes retained by the ledger

func (*Ledger[T]) Get

func (l *Ledger[T]) Get(id string) (Record[T], bool)

Read a record by its operation ID

func (*Ledger[T]) Len

func (l *Ledger[T]) Len() int

Return the number of retained operation records

func (*Ledger[T]) Records

func (l *Ledger[T]) Records(group string) []Record[T]

List retained records for an operation group

func (*Ledger[T]) Reserve

func (l *Ledger[T]) Reserve(group string, value T, cost int) (Record[T], error)

Reserve succeeds before the caller submits a new external operation. It never evicts history automatically, including when all retained records are terminal

func (*Ledger[T]) Retire

func (l *Ledger[T]) Retire(active map[string]bool) []string

Retire forgets only terminal, unpinned records from inactive groups. Pending and uncertain outcomes remain until the caller explicitly reconciles their state

func (*Ledger[T]) Update

func (l *Ledger[T]) Update(id string, state State, value T, cost int, pinned bool) error

Update an operation outcome without exceeding its byte budget

type Record

type Record[T any] struct {
	ID, Group string
	Sequence  uint64
	State     State
	Pinned    bool
	Value     T
	Cost      int
}

type State

type State string
const (
	Pending   State = "pending"
	Confirmed State = "confirmed"
	Failed    State = "failed"
	Uncertain State = "uncertain"
)

Jump to

Keyboard shortcuts

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