generation

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package generation provides atomic collector generation swaps. Work leases stay attached to the generation in which they started, and reset waits for those leases before freezing the old value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frozen

type Frozen[S any] struct {
	Generation int64
	Value      S
}

Frozen is an immutable-by-contract snapshot of one generation.

type Lease

type Lease[T any, S any] struct {
	// contains filtered or unexported fields
}

Lease pins work to the generation in which it started.

func (*Lease[T, S]) Done

func (l *Lease[T, S]) Done()

Done releases the lease. It is safe to call more than once.

func (*Lease[T, S]) Generation

func (l *Lease[T, S]) Generation() int64

Generation returns the pinned generation number.

func (*Lease[T, S]) Value

func (l *Lease[T, S]) Value() T

Value returns the mutable collector owned by the pinned generation.

type Manager

type Manager[T any, S any] struct {
	// contains filtered or unexported fields
}

Manager owns a current generation and serializes resets.

func New

func New[T any, S any](factory func() T, snapshot func(T) S) *Manager[T, S]

New constructs a manager whose first generation is 1.

func (*Manager[T, S]) Acquire

func (m *Manager[T, S]) Acquire() *Lease[T, S]

Acquire pins and returns the current generation.

func (*Manager[T, S]) CurrentGeneration

func (m *Manager[T, S]) CurrentGeneration() int64

CurrentGeneration returns the generation accepting new work.

func (*Manager[T, S]) Snapshot

func (m *Manager[T, S]) Snapshot() Frozen[S]

Snapshot takes a best-effort snapshot of the current generation. The value must provide its own synchronization against active leases.

func (*Manager[T, S]) SwapAndSnapshot

func (m *Manager[T, S]) SwapAndSnapshot() Frozen[S]

SwapAndSnapshot publishes a new empty generation, waits for work pinned to the old generation, and then freezes the old value. Concurrent swaps are serialized so frozen generations are returned in order.

Jump to

Keyboard shortcuts

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